Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I have a web form that has textboxes and RangeValidator. The validator works and displays but when you tab to another textbox it disappears. Why is that? What setting did I forget?

ASP.NET
<asp:RangeValidator ID="RangeValidatorLY1" runat="server" 
                    ControlToValidate="TextBox1" CssClass="style40" 
                    ErrorMessage="20% Difference. Please verify numbers" ForeColor="Red" 
                    Type="Integer" Enabled="True" Display="Dynamic"></asp:RangeValidator>


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


I also have a code behind that formats the value in the textbox.

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


I also have a code behind for the validator.

C#
double txtVal = Convert.ToDouble(TextBoxLY1.Text);
        double minVal = (txtVal * 0.8);
        double maxVal = (txtVal * 1.2);
        RangeValidatorLY1.MinimumValue = minVal.ToString();
        RangeValidatorLY1.MaximumValue = maxVal.ToString();


Here is what is in my textbox text change:
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        int w = Convert.ToInt32(TextBox1.Text.Replace(",", ""));
        int v = 0;
        TextBox2.Text = Convert.ToString(w + v);
        RangeValidatorLY1.Validate();
        //TextBoxFTUG.Text = Math.Round(Convert.ToDouble(TextBox1.Text), 2).ToString();
        TextBox1.Text = string.Format("{0:0,0}", double.Parse(TextBox1.Text));
        TextBox3.Focus();

    }
Posted
Comments
/\jmot 17-Oct-14 10:49am    
Try using validationGroup.
Computer Wiz99 17-Oct-14 11:11am    
Never used it before. How would that be setup?
/\jmot 17-Oct-14 11:51am    
Search google,how to use validation group in asp.net.
Computer Wiz99 17-Oct-14 12:04pm    
Thanks
/\jmot 17-Oct-14 15:41pm    
you found your solution?

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