I have a web form that has two textboxes on it. I also have a RangeValidator on the web form for the textboxes.
Here is the properties for the RangeValidator:
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox2" CssClass="style40"
ErrorMessage="20% Difference. Please verify numbers" ForeColor="Red"
Type="Integer" Enabled="True" Display="Dynamic"></asp:RangeValidator>
Textbox2 properties:
<asp:TextBox ID="TextBox2" runat="server" Width="180px" AutoPostBack="False"
ontextchanged="TextBox2_TextChanged">0</asp:TextBox>
Textbox1 is data from the database.
Textbox1 properties:
<asp:TextBox ID="TextBoxLYFTUG" runat="server" Width="180px"
ReadOnly="True" Enabled="False"></asp:TextBox>
Here is the code behind for the RangeValidator:
double txtVal6 = Convert.ToDouble(TextBox1.Text);
double minVal6 = (txtVal * 0.8);
double maxVal6 = (txtVal * 1.2);
RangeValidator1.MinimumValue = minVal6.ToString();
RangeValidator1.MaximumValue = maxVal6.ToString();
As the code is right now it works fine. The RangeValidator fires the error message.
When apply the format code for textbox2 and setting the AutoPostBack to True, the RangeValidator does not fire but the data is formatted.
Here is the format code:
TextBox1.Text = string.Format("{0:0,0}", double.Parse(TextBox1.Text));
Is there a way to keep the format and fire the validator on point? Or is there a work around that will work better?