473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

validate multiple controls

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;
}

Jun 20 '06 #1
6 1577
On the onclientclick of the submit button, call a javascript function
that will validate the controls, if something doesnt check out, then
you can use javascript to cancel the post.

Sorry i dont have any code, not at my home computer right now.

Willem wrote:
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;
}


Jun 20 '06 #2
thanks for responding. It means I have to add the code using the
stringbuilder, so I get the proper clientid's of the controls. Bit of
work, but no problem.

Do you happen to know how I can cancel the submit from this event?
Never mind: just solved that with:
OnClientClick="if(!checkDifferences())return false;".
Weird that OnClientClick="checkDifferences();" doesn't work.

Thanks for the tip.

dkode schreef:
On the onclientclick of the submit button, call a javascript function
that will validate the controls, if something doesnt check out, then
you can use javascript to cancel the post.

Sorry i dont have any code, not at my home computer right now.

Willem wrote:
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;
}


Jun 20 '06 #3
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;
}

Jun 20 '06 #4
lol ... very nice Vallim. I appreciate the effort you put into it. But
this would leave me with a submitted form (with unvalidated data) and
no opportunity to repost it with correct data as the submit button has
been disabled.

Of course I can show a message instead of disableing the button, but I
rather do my validation client-side.

Jun 20 '06 #5
Just my 2cents,

I always try to use validation controls from dotnet, I try to shy away
from doing client side validation.

It might be easier to implement and use less bandwidth, but in the long
run if business requirements change in your middle tier, then you are
forced to change the middle tier and the outputted javascript code that
is sent to the client.

Just makes for more places you are spreading your business requirements
to, and I always see client side javascript as a maintenance headache.

Just a matter of preference depending on the project, I have done
clientside validation before when absolutely required, but I try to
stay away from it.

sean

Willem wrote:
lol ... very nice Vallim. I appreciate the effort you put into it. But
this would leave me with a submitted form (with unvalidated data) and
no opportunity to repost it with correct data as the submit button has
been disabled.

Of course I can show a message instead of disableing the button, but I
rather do my validation client-side.


Jun 20 '06 #6
The dotnet controls use client script as well. They are simply not
sufficient though. Especially if you need to validate between multiple
controls. The base validator object expects a single control and not a
collection or controls. I actually assume this will be different in
asp.net 3.

Jun 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
4
by: msnews.microsoft.com | last post by:
I have 2 datagrids. Each with an add record in the footer. How can I just validate the fields in that datagrid without validating the fields in the 2nd datagrid. Any examples??? -- David
9
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.