Hi Willem
The below code do all the validation required by you in server side. The
validation is done on the Click Event of the SubmitBtn. If the validation
results holds true the Submit button will be enabled otherwise it will be
disabled.
protected void SubmitBtn_OnClick(object sender, EventArgs e)
{
bool validOutput = CheckForValidation();
if (validOutput == true)
{
SubmitBtn.Enabled = true;
}
else
{
SubmitBtn.Enabled = false;
}
}
protected bool CheckForValidation()
{
if ((txt_MinA.Text != string.Empty) && (txt_MaxA.Text != string.Empty))
{
int AMaxValue = System.Convert.ToInt16(txt_MaxA.Text);
int AMinValue = System.Convert.ToInt16(txt_MinA.Text);
if (AMaxValue - AMinValue > 25)
{
return false;
}
if ((txt_MinB.Text != string.Empty) && (txt_MaxB.Text != string.Empty))
{
int BMaxValue = System.Convert.ToInt16(txt_MaxB.Text);
int BMinValue = System.Convert.ToInt16(txt_MinB.Text);
if (BMaxValue - BMinValue > 25)
{
return false;
}
}
else
{
return false;
}
if ((txt_MinC.Text != string.Empty) && (txt_MaxC.Text != string.Empty))
{
int CMaxValue = System.Convert.ToInt16(txt_MaxC.Text);
int CMinValue = System.Convert.ToInt16(txt_MinC.Text);
if (CMaxValue - CMinValue > 25)
{
return false;
}
}
else
{
return false;
}
if ((txt_MinD.Text != string.Empty) && (txt_MaxD.Text != string.Empty))
{
int DMaxValue = System.Convert.ToInt16(txt_MaxD.Text);
int DMinValue = System.Convert.ToInt16(txt_MinD.Text);
if (DMaxValue - DMinValue > 25)
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
return true;
}
Let me know if u have any doubts.
Regards,
Valli
[
www.syncfusion.com http://www.syncfusion.com/faq/aspnet/default.aspx]
"Willem" <ww*********@gmail.com> wrote in message
news:11*********************@h76g2000cwa.googlegro ups.com...
I have got a very simple javascript which compares about 8 controls in
pairs of two. i.e. maxA - minA <= 25.
Now I would like it to be triggered for validation (before submit?) and
cancel the submit if neccessary. Very easy to do if it were plain HTML.
No idea how to implement this in ASP.NET 2 though. Can someone please
point me in the right direction?
the script:
function checkDifferences()
{
var msg;
if (txt_MinA.value != "" && txt_MaxA.value != "")
{
if (txt_MaxA.value - txt_MinA.value > 25)
{
msg = "A: The difference can't be over 25 mm.\n";
}
}
if (txt_MinB.value != "" && txt_MaxB.value != "")
{
if (txt_MaxB.value - txt_MinB.value > 25)
{
msg += "B: The difference can't be over 25 mm.\n";
}
}
if (txt_MinC.value != "" && txt_MaxC.value != "")
{
if (txt_MaxC.value - txt_MinC.value > 25)
{
msg += "C: The difference can't be over 25 mm.\n";
}
}
if (txt_MinD.value != "" && txt_MaxD.value != "")
{
if (txt_MaxD.value - txt_MinD.value > 25)
{
msg += "D: The difference can't be over 25 mm.\n";
}
}
return msg;
}