?
Solved

RangeValidator accepts empty textbox

Posted on 2009-07-01
4
Medium Priority
?
797 Views
Last Modified: 2012-05-07
I have a textbox that requires the user enter a number into.
In order to make sure they enter something and it is a valid integer I thought a rangevalidator would do the trick where the range is 0 -99999
If they try to enter text or 0.5 then everything works fine but if they have an empty text box or spaces then the form is submitted. Did I miss something?

<asp:RangeValidator ID="RangeValidator1" runat="server"
                        ControlToValidate="txtHoursLost" ErrorMessage="*Invalid value"
                        ForeColor="White" MaximumValue="99999" MinimumValue="0" Type="Integer"></asp:RangeValidator>
0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 2000 total points
ID: 24759511
It accepts an empty box because it is not required. Use a RequiredValidator with the RangeValidator.
0
 
LVL 29

Author Comment

by:QPR
ID: 24759720
hmmm so 2 validators tied to the same control. ok done that.
Seems to work ok until the person 9successfully) enters:
 "               7" for example.
Should the range validator not recognise that this is not an integer?
Yes I could start trimming stuff and doing further validations in the code behind but....?
0
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 24759920
I believe the behavior is because all TextBox.Text properties are strings and must be converted to an integer before validating the range. The Interger.TryParse method will return True when supplied with the string "      7", therefore that string represents the integer 7.

I looked it up:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.rangevalidator.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basecomparevalidator.type.aspx
0
 
LVL 15

Expert Comment

by:jinal
ID: 24760429
TRy to look for customvalidator or regualrexpression validator. It will give you more control over validation.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question