473,407 Members | 2,598 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,407 software developers and data experts.

Customize the client side validation in asp.net

Hi,

I am trying to customize the asp.net validation to achieve the following:

Upon submitting the form, client side validation will run, and it will stop
at the first error detected. For example if both UserID and Password text
fields are required but neither is filled in, I'd like to display the error
message (a dialogbox) "Please enter the User ID". And only after the user
has filled in UserID, it will display "Please enter the Password".

Initially I thought this should be an easy thing to do (I still believe so),
but I have spent a few hours and still could not find a good solution. The
validator controls / summary controls are too inflexible to achieve this. I
am willing to write all the validation logic myself, but I don't know how do
I hook my logic to the existing client validation flow.

Any help is appreciated.

OnlyGo
Nov 19 '05 #1
5 1908
Hello,

I'm not sure you can do that with the ASP.NET validation controls.

But if you do your own validation you can easily accomplish what you want
using JavaScript such as this one:

function LengthCheck()
{
if (document.formName.txtName.value.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formName.txtPassword.value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.aspx" method="post" name="formName" onSubmit="return
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi,

I am trying to customize the asp.net validation to achieve the following:

Upon submitting the form, client side validation will run, and it will
stop
at the first error detected. For example if both UserID and Password text
fields are required but neither is filled in, I'd like to display the
error
message (a dialogbox) "Please enter the User ID". And only after the user
has filled in UserID, it will display "Please enter the Password".

Initially I thought this should be an easy thing to do (I still believe
so),
but I have spent a few hours and still could not find a good solution. The
validator controls / summary controls are too inflexible to achieve this.
I
am willing to write all the validation logic myself, but I don't know how
do
I hook my logic to the existing client validation flow.

Any help is appreciated.

OnlyGo

Nov 19 '05 #2
You should be able to easily do this with the validator controls. Using the
validation summary, you should be able to get a popup message displaying
what you require also. On the ValidationSummary control, enable the
'ShowMessageBox' property to get the dualog box. Ad some requiredfield
validators for each field you require and sets its error msg property
appropriately. Thats about it.

--

- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)
"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
Hello,

I'm not sure you can do that with the ASP.NET validation controls.

But if you do your own validation you can easily accomplish what you want
using JavaScript such as this one:

function LengthCheck()
{
if (document.formName.txtName.value.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formName.txtPassword.value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.aspx" method="post" name="formName" onSubmit="return
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi,

I am trying to customize the asp.net validation to achieve the following:
Upon submitting the form, client side validation will run, and it will
stop
at the first error detected. For example if both UserID and Password text fields are required but neither is filled in, I'd like to display the
error
message (a dialogbox) "Please enter the User ID". And only after the user has filled in UserID, it will display "Please enter the Password".

Initially I thought this should be an easy thing to do (I still believe
so),
but I have spent a few hours and still could not find a good solution. The validator controls / summary controls are too inflexible to achieve this. I
am willing to write all the validation logic myself, but I don't know how do
I hook my logic to the existing client validation flow.

Any help is appreciated.

OnlyGo


Nov 19 '05 #3
As already mentioned the built in validation controls allow most of what
you're looking for. The <asp:CustomValidator> allows you to write you own
custom client side javascript validation and server side validation code
too (You should always do the server side piece, as a client can disable
javascript). Also there is the <asp:ValidationSummary> that can do message
boxes if you'd like or HTML to show the user a list of the errors. The one
aspect in which it diverges from what you're looking for is that the summary
will show all current errors on the page, as opposed to just the first one
it encounters. If you want to use a framework to expediate your development
process, you sometimes have to defer to its particular quirks. If you don't
like how it works, then you can build your own, but then you're going to
be spending more time in development.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I am trying to customize the asp.net validation to achieve the
following:

Upon submitting the form, client side validation will run, and it will
stop at the first error detected. For example if both UserID and
Password text fields are required but neither is filled in, I'd like
to display the error message (a dialogbox) "Please enter the User ID".
And only after the user has filled in UserID, it will display "Please
enter the Password".

Initially I thought this should be an easy thing to do (I still
believe so), but I have spent a few hours and still could not find a
good solution. The validator controls / summary controls are too
inflexible to achieve this. I am willing to write all the validation
logic myself, but I don't know how do I hook my logic to the existing
client validation flow.

Any help is appreciated.

OnlyGo


Nov 19 '05 #4
Thanks Andrei, that works. I was trying the similar approach by hooking up
the validation function to the submit button itself. And because of some
validation control, the submit button has already had a onclick() handler
and that's why I don't know how my function can be hooked up to that.

The form onSubmit handler completely solves my problem.

Thanks again.

Sun Jian

"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
Hello,

I'm not sure you can do that with the ASP.NET validation controls.

But if you do your own validation you can easily accomplish what you want
using JavaScript such as this one:

function LengthCheck()
{
if (document.formName.txtName.value.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formName.txtPassword.value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.aspx" method="post" name="formName" onSubmit="return
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi,

I am trying to customize the asp.net validation to achieve the following:
Upon submitting the form, client side validation will run, and it will
stop
at the first error detected. For example if both UserID and Password text fields are required but neither is filled in, I'd like to display the
error
message (a dialogbox) "Please enter the User ID". And only after the user has filled in UserID, it will display "Please enter the Password".

Initially I thought this should be an easy thing to do (I still believe
so),
but I have spent a few hours and still could not find a good solution. The validator controls / summary controls are too inflexible to achieve this. I
am willing to write all the validation logic myself, but I don't know how do
I hook my logic to the existing client validation flow.

Any help is appreciated.

OnlyGo


Nov 19 '05 #5
Thanks Brock and Paul!

I understand fully the trandoffs between rolling out my own framework and
using the existing one. There are actually 2 reasons I wanted to do this.
One reason is that I am doing some javascript/DHTML stuff in my page that
conflicts with the client side validation script from asp.net, which is very
messy to debug. Another reason is that I have heard many times that asp.net
is very extensible. And I wanted to take this opportunity to learn by doing
things that are not designed to work by default ;)

Sun Jian

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:60**********************@msnews.microsoft.com ...
As already mentioned the built in validation controls allow most of what
you're looking for. The <asp:CustomValidator> allows you to write you own
custom client side javascript validation and server side validation code
too (You should always do the server side piece, as a client can disable
javascript). Also there is the <asp:ValidationSummary> that can do message
boxes if you'd like or HTML to show the user a list of the errors. The one
aspect in which it diverges from what you're looking for is that the summary will show all current errors on the page, as opposed to just the first one
it encounters. If you want to use a framework to expediate your development process, you sometimes have to defer to its particular quirks. If you don't like how it works, then you can build your own, but then you're going to
be spending more time in development.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I am trying to customize the asp.net validation to achieve the
following:

Upon submitting the form, client side validation will run, and it will
stop at the first error detected. For example if both UserID and
Password text fields are required but neither is filled in, I'd like
to display the error message (a dialogbox) "Please enter the User ID".
And only after the user has filled in UserID, it will display "Please
enter the Password".

Initially I thought this should be an easy thing to do (I still
believe so), but I have spent a few hours and still could not find a
good solution. The validator controls / summary controls are too
inflexible to achieve this. I am willing to write all the validation
logic myself, but I don't know how do I hook my logic to the existing
client validation flow.

Any help is appreciated.

OnlyGo


Nov 19 '05 #6

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

Similar topics

4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
3
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of...
4
by: | last post by:
Hi Has anyone any experience using client side validation with asp.net forms. Specifically I'd like to know... 1. How do you attach client side code web controls (a button), like a...
1
by: rmgalante | last post by:
I have written an ASP.Net application that uses the standard client-side and server-side validation for various fields on the form. Some of the customers that use the form report symptoms that...
1
by: vidya | last post by:
Hi, I have a button which is a web control. I have some validation in javascript for the button in .aspx file and some in the button onclick event in code behind(C#). I need to get through both...
1
by: Hong Hao | last post by:
Recently, I was trying to modify an existing aspx page when client-side validation on that page stopped working. I searched this group and the web in general and found that other people have had...
4
by: Chris | last post by:
Hi, i want to validate a textbox like this: <asp:TextBox ID="vrg" runat="server" Width="495px" TextMode=MultiLine/> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"...
2
by: goscottie | last post by:
I need to find a way to either 1. run and check all Validation controls (in my case one CompareValidator) and run client side javascript function. In this case I'll use <asp:Button>. So if all...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.