Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two RangeValidators. They are firing but not correctly. When the user enters their numbers and tabs to the next textbox the RV will fire if the new number is 40% higher than the old number. The same goes for the other RV if the new number is 50% higher that the old number. When the user enters the same number as the old number and clicks Submit the RV fires. What calculation did I do wrong? I just want to fire the RV if there is an 40% and 50% increase.

This is the 40% increase RV:
C#
int itxtVal6 = Convert.ToInt32(TextBoxLY1.Text);
        int iminVal6 = itxtVal6;
        int imaxVal6 = itxtVal6 * (140 / 100);
        RangeValidatorLY1.MinimumValue = iminVal6.ToString();
        RangeValidatorLY1.MaximumValue = imaxVal6.ToString();


This is the 50% increase RV:
C#
int itxtVal12 = Convert.ToInt32(TextBoxLY2.Text);
        int iminVal12 = itxtVal12;
        int imaxVal12 = itxtVal12 * (150 / 100);
        RangeValidatorLY2.MinimumValue = iminVal12.ToString();
        RangeValidatorLY2.MaximumValue = imaxVal12.ToString();
Posted
Comments
jkirkerx 24-Oct-14 16:30pm    
I gave up on the Microsoft validators years ago, and went jquery or javascript to validate values before posting or hitting the submit button.

In a production environment, they were unreliable.
Computer Wiz99 24-Oct-14 16:36pm    
I don't know jquery. Can n uou give me an example.

1 solution

This is based on the comment above, saying that I don't use the Microsoft Validators anymore, gave up on them years ago.

I indicated that I use JQuery and Javascript to validate forms. So ...

You start here,
http://learn.jquery.com/about-jquery/how-jquery-works/[^]

Create a blank jscript file using solution explorer, name it rangeValidator.js or something, and drag the file from the solution explorer into the head tag.
<head>
 <script src="jquery.js"></script>
 <script src="rangeValidator.js"></script>
</head>


Write your script
function validate_40() {
    var vFlag = true;
    var itxtVal6_txt, itxtVal6_int, iminVal_int, imaxVal6_int;
    itxtVal6_txt =  $('#TextBoxLY1').val();
    iminVal6_int = parseInt(itxtVal6_txt);
    imaxVal6_int = parseInt(iminVal6_int * 140 / 100);
    if (!some formula) {
      vFlag = false;
    }
    return vFlag;
}


Then on your button
<asp:textbox id="TextBoxLY1" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="submit" runat="server" onclientclick="return validate_40();" xmlns:asp="#unknown"></asp:button>


I'm not going to tackle the formula, perhaps someone can edit this and fix any errors or expand on it.
 
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