Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have an issue with a rangevalidator of my web form. I have six textboxes and three rangevalidators. Three of the textboxes are populated data from the database and the other three textboxes are for new data to be submitted to the database. What is happening is when the user is logged on and clicks the link to the form it loads the form with an error:
HTML
"The value '385.2' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Integer'.".
The value that is loading from the database is 321. I am trying to find out if the new number is 20% lower or 20% higher than the old number (from database).

Here is my code for the RangeValidator:
C#
double txtVal = Convert.ToDouble(TextBox1.Text);
        double minVal = (txtVal * 0.8);
        double maxVal = (txtVal * 1.2);
        RangeValidator1.MinimumValue = minVal.ToString();
        RangeValidator1.MaximumValue = maxVal.ToString();


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


Is there a way to correct this and still get the value I need for the RangeValidator to work correctly?
Posted
Updated 21-Oct-14 14:06pm
v2
Comments
Kornfeld Eliyahu Peter 21-Oct-14 16:59pm    
You may show us the markup for the validator troubles you...

The validator Type and Value set need to match, look here http://msdn.microsoft.com/en-us/library/85y3x2a2(v=vs.110).aspx[^]

public enum ValidationDataType
The ValidationDataType enumeration represents the different data types that the CompareValidator and RangeValidator controls can validate.

So, either change Type="Double" or cast the double to an int
 
Share this answer
 
I have used this and it works.
C#
int itxtVal11 = Convert.ToInt32(TextBox1.Text);
        int iminVal11 = (itxtVal11 - itxtVal11 * 20 / 100);
        int imaxVal11 = (itxtVal11 + itxtVal11 * 20 / 100);
        RangeValidatorLYTNNCC.MinimumValue = iminVal11.ToString();
        RangeValidatorLYTNNCC.MaximumValue = imaxVal11.ToString();
 
Share this answer
 

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