473,466 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to: Use RangeValidator Control

I've configured a RangeValidator control on a WebForm, using ASP.NET, and
have set the type to string, the max value to 100, and min value to 1,
however, the control to validate always throws an error, regardless of the
length of the string. For example...

<asp:textbox id="txtQuestion" runat="server" Width="400px" MaxLength="100"
Height="50px" TextMode="MultiLine" CssClass="text1"></asp:textbox>

<asp:RangeValidator id="RangeValidatorQuestion1" runat="server"
ControlToValidate="txtQuestion" ErrorMessage="Question length cannot exceed
100 characters." MinimumValue="1" MaximumValue="100">*</asp:RangeValidator>

<asp:Button id="btnSubmit" runat="server" Text="Button"
CausesValidation="true"></asp:Button>

Any ideas why this isn't working? Thanks.

Nov 16 '05 #1
5 17309
Hi,

The rangevalidator control checks that an input value falls between two
values that are specified in the control. It does not take the length of the
input for the control that is being validated and then validate against that
value. One easy way that you could implement this type of functionality is
to use a custom validator control and write code that checks the
Trim().Length of the textbox. I am sure that there are many more. You may
want to look in the asp.net news groups for more implementations.

I hope this helps.
Nov 16 '05 #2
On Thu, 20 Jan 2005 02:17:02 -0800, charliewest wrote:
I've configured a RangeValidator control on a WebForm, using ASP.NET, and
have set the type to string, the max value to 100, and min value to 1,
however, the control to validate always throws an error, regardless of the
length of the string. For example...

<asp:textbox id="txtQuestion" runat="server" Width="400px" MaxLength="100"
Height="50px" TextMode="MultiLine" CssClass="text1"></asp:textbox>

<asp:RangeValidator id="RangeValidatorQuestion1" runat="server"
ControlToValidate="txtQuestion" ErrorMessage="Question length cannot exceed
100 characters." MinimumValue="1" MaximumValue="100">*</asp:RangeValidator>

<asp:Button id="btnSubmit" runat="server" Text="Button"
CausesValidation="true"></asp:Button>

Any ideas why this isn't working? Thanks.


The RangeValidator does just that, validates that the value entered is
within a certain range. It does not validate length. So when you specify
the range is "1" to "100", that means that the only allowed values are 1,
2, 3, 4, ... 99, 100.

You will either want to use a custom validator and provide your own script,
or a RegularExpressionValidator. However you have already set a max value
on the input field, so they shouldn't be able to enter more than 100
characters with that set. If by min length of 1 you are trying to make the
field required, then add a RequiredFieldValidator to your page.
--
Tom Porterfield
Nov 16 '05 #3
Tom, i've been trying to figure out in other newsgroups, why the max value
doesn't work for the text box. My conclusion is simply that when the text box
is set to mulit-line, it renders as a text area control on the page and that
the maxlength attribute is no longer valid. Can you confirm this?

"Tom Porterfield" wrote:
On Thu, 20 Jan 2005 02:17:02 -0800, charliewest wrote:
I've configured a RangeValidator control on a WebForm, using ASP.NET, and
have set the type to string, the max value to 100, and min value to 1,
however, the control to validate always throws an error, regardless of the
length of the string. For example...

<asp:textbox id="txtQuestion" runat="server" Width="400px" MaxLength="100"
Height="50px" TextMode="MultiLine" CssClass="text1"></asp:textbox>

<asp:RangeValidator id="RangeValidatorQuestion1" runat="server"
ControlToValidate="txtQuestion" ErrorMessage="Question length cannot exceed
100 characters." MinimumValue="1" MaximumValue="100">*</asp:RangeValidator>

<asp:Button id="btnSubmit" runat="server" Text="Button"
CausesValidation="true"></asp:Button>

Any ideas why this isn't working? Thanks.


The RangeValidator does just that, validates that the value entered is
within a certain range. It does not validate length. So when you specify
the range is "1" to "100", that means that the only allowed values are 1,
2, 3, 4, ... 99, 100.

You will either want to use a custom validator and provide your own script,
or a RegularExpressionValidator. However you have already set a max value
on the input field, so they shouldn't be able to enter more than 100
characters with that set. If by min length of 1 you are trying to make the
field required, then add a RequiredFieldValidator to your page.
--
Tom Porterfield

Nov 16 '05 #4
On Tue, 25 Jan 2005 03:07:02 -0800, charliewest wrote:
Tom, i've been trying to figure out in other newsgroups, why the max value
doesn't work for the text box. My conclusion is simply that when the text box
is set to mulit-line, it renders as a text area control on the page and that
the maxlength attribute is no longer valid. Can you confirm this?


No. As I said, there is no maxlength property for a RangeValidator.
Rather it is as you said a MaximumValue property, and it determines just
that. Is the data entered in the control, not the length of the data but
the actual data value, greater than the specified MaximumValue.
--
Tom Porterfield
Nov 16 '05 #5
On Tue, 25 Jan 2005 06:46:03 -0500, Tom Porterfield wrote:
On Tue, 25 Jan 2005 03:07:02 -0800, charliewest wrote:
Tom, i've been trying to figure out in other newsgroups, why the max value
doesn't work for the text box. My conclusion is simply that when the text box
is set to mulit-line, it renders as a text area control on the page and that
the maxlength attribute is no longer valid. Can you confirm this?


No. As I said, there is no maxlength property for a RangeValidator.
Rather it is as you said a MaximumValue property, and it determines just
that. Is the data entered in the control, not the length of the data but
the actual data value, greater than the specified MaximumValue.


Sorry, re-reading this I see you are not talking about range validators
anymore but only properties on the TextBox control. You are correct. When
a System.Web.UI.WebControls.TextBox has its TextMode property set to
MultiLine it renders client side as a TEXTAREA, which does not support the
MAXLENGTH property. Unfortunately the control hasn't been coded with the
smarts to disable the MaxLength property in the designer when the TextMode
property has been set to MultiLine.
--
Tom Porterfield
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andres Romero | last post by:
I need to validate that a user enters (in a TextBox) only the values 1, 2, 4. 6, 8, 10 or 20. Using the RangeValidator control, it only accepts the min and max value. Is there any other control or...
6
by: jk | last post by:
Looking through WebUIValidation.js, I discovered that the standard validators don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would like to do To keep code to a minimum, I...
2
by: Lucas Tam | last post by:
Hi all, I have a RangeValidator that is not working correctly - it is always returning a isValid = False. The Javascript is returning this as well as on the server side. My RangeValidator...
1
by: BobRoyAce | last post by:
I have a RangeValidator control on a page that is supposed to make sure that the user does not enter a value outside of the range 0-nn.nn, where nn.nn is some monetary value. For example, let's say...
0
by: Arpicheck | last post by:
Hi, I am writing a page that contains a texbox, a calendar, and a rangevalidator. The range validator is testing the textbox for date values. There is an event, set up to fire, when the...
1
by: deast_98 | last post by:
My web application deployed to the server does not respond to button clicks, but these do work in development. I removed the only range validation control, associated to a textbox, then redeployed...
11
by: Axel Dahmen | last post by:
Hi, I'm working in a team developing an international website. When I set the page's CultureInfo to Hungarian (hu-HU) then the RangeValidator doesn't seem to be able to parse a TextBox's date...
2
by: bpd | last post by:
I have a user control embedded in a gridview as an EditItemTemplate. When updating, the value is not saved to the database. I have an SQLDataSource attached to the Gridview. Can someone point me...
1
by: =?Utf-8?B?SGlwSG9wcGVy?= | last post by:
Hi, I have a composited control with a Textbox and a Rangevalidator. If I am not mistaken, Rangevalidator should take currency ($) symbol, but I got the validation error when user enter -$100...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.