I am trying to use RangeFieldValidator for a username and password. The username suppose to be at least three characters long and the password at least five characters long. I am using the datatype as string, validating the textbox correctly, but I don't know how to set the minimum and maximum values for the string.
I think I can't use 3 and 5 for the min and max values, since it is string datatype.
I add the onclick event in the RangeValidator to go to the function check_length. And used the .Length method of string to compare the length of input.
But when I start typing in the TextBox1 it shows the RangeValidator ErrorMessage even if the length is correct. I guess this is because the onclick event.
Should I use a different event. I am totally new to .Net and scripting language, so please help me out.
I do not use the validators myself, I do not like them because asp.net otuputs js with them and it outputs a bit of invalid code. Here is what I would do, I would put in the script that you are executeing on click of that command button at the bottom, as buntine said, and if statement
if len(yourtextbox) < 3 and len(youtextbox) > 5 then
lblerrormsg.visible="true"
else
<code to be executed if the textbox length is how you wanted it>
end if
lblerrormsg would be an asp lable right after your text box.
Code:
<asp:Label
id="lblerrormesg"
Text="this feild is required<br>"
runat="server"
visible="false" enableViewState="False"
/>
Originally posted by talal RangeValidator to use, it looks a good control if I figure out to use in this scenario.
Thanks,
Talal
None of the validators are 'good' controls in my opinion. They are bad until version 1.1 if microsoft decides to fix their output. I do not use the built in pageing and some of the other built in features either, because they limit me and output js that does not have a type attribute.
Bookmarks