Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a web form that displays different error messages. I am using the Range Validator for displaying the error message. When a user enters in a number the error message displays very quickly. I changed my properties to EnableClientScript= true Display= Dynamic and get the same issue. The textbox is formatted with a code to add commas where needed. Here is the code behind:

C#
TextBoxFTUG.Text = string.Format("{0:0,0}", double.Parse(TextBoxFTUG.Text));


Here are the properties for the textbox:

ASP.NET
<asp:TextBox ID="TextBoxFTUG" runat="server" Width="180px" AutoPostBack="True" 
                    ontextchanged="TextBoxFTUG_TextChanged">0</asp:TextBox>


The AutoPost Back is there to change the data to the format when the user clicks or tabs to the next textbox.

I also have a code behind that does calculations for the RangeValidator.

C#
double txtVal6 = Convert.ToDouble(TextBoxLYFTUG.Text);
        double minVal6 = (txtVal * 0.8);
        double maxVal6 = (txtVal * 1.2);
        RangeValidatorLYFTUG.MinimumValue = minVal6.ToString();
        RangeValidatorLYFTUG.MaximumValue = maxVal6.ToString();


When the user clicks on the submit button all of the errors display that should have displayed earlier. How can I get the error to display when the user enters data that is 20% higher/lower in the textbox?
Posted
Updated 13-Oct-14 5:11am
v4

1 solution

Hi,

Have you had a look at the Validation Summary control?

[edit]
It will also help the validation appear more fluid if you add the following properties to your validator controls:
HTML
EnableClientScript="true"
Display="Dynamic"

[/edit]


Hope it helps.
 
Share this answer
 
v2
Comments
Computer Wiz99 10-Oct-14 10:48am    
Thanks hypermellow. Will this also reset the error message when the user changes the number? EX: If the user enters 12,345 and the error displays and the user should have entered 123,456. Will the error go away?
hypermellow 10-Oct-14 11:00am    
Yup, it should do - as setting EnableClientScript to true should perform the initial validation in the browser (without a postback) via client script.
... also, it's worth noting that even though the validation is performed client side, it is important to confirm the validation was successful on the server too by checking Page.IsValid() in your code behind.
Computer Wiz99 10-Oct-14 11:39am    
Where would I put Page.IsValid() in code behind? I did change the properties to the validation but is still not working.
hypermellow 13-Oct-14 5:37am    
I see you've changed your question now, what do you mean the validation is still not working?
The check for Page.IsValid() should go in the event handler for the submit button click.
Computer Wiz99 13-Oct-14 5:51am    
When the user enters their data and tab to the next textbox it should fire. This needs to happen without clicking the submit button. It was working before I formatted the textbox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900