473,888 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 checkDifference s()
{
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 1596
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 checkDifference s()
{
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(!checkDiffer ences())return false;".
Weird that OnClientClick=" checkDifference s();" 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 checkDifference s()
{
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_OnCli ck(object sender, EventArgs e)

{

bool validOutput = CheckForValidat ion();

if (validOutput == true)

{

SubmitBtn.Enabl ed = true;

}

else

{

SubmitBtn.Enabl ed = false;

}

}

protected bool CheckForValidat ion()

{

if ((txt_MinA.Text != string.Empty) && (txt_MaxA.Text != string.Empty))

{

int AMaxValue = System.Convert. ToInt16(txt_Max A.Text);

int AMinValue = System.Convert. ToInt16(txt_Min A.Text);

if (AMaxValue - AMinValue > 25)

{

return false;

}

if ((txt_MinB.Text != string.Empty) && (txt_MaxB.Text != string.Empty))

{

int BMaxValue = System.Convert. ToInt16(txt_Max B.Text);

int BMinValue = System.Convert. ToInt16(txt_Min B.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_Max C.Text);

int CMinValue = System.Convert. ToInt16(txt_Min C.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_Max D.Text);

int DMinValue = System.Convert. ToInt16(txt_Min D.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*********@gm ail.com> wrote in message
news:11******** *************@h 76g2000cwa.goog legroups.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 checkDifference s()
{
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
3008
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 a method for the form?. If I give it an empty action <form action="" ..... it validates OK. Is this acceptable or is there a better/standards correct way? Thanks.
4
1460
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
6703
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 something like textbox1 through textbox10? Thanks
11
11776
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11181
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.