473,583 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1916
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.formN ame.txtName.val ue.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formN ame.txtPassword .value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.as px" method="post" name="formName" onSubmit="retur n
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotma il.com> wrote in message
news:eF******** ******@tk2msftn gp13.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 ValidationSumma ry 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**********@g eekpedia.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.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.formN ame.txtName.val ue.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formN ame.txtPassword .value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.as px" method="post" name="formName" onSubmit="retur n
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotma il.com> wrote in message
news:eF******** ******@tk2msftn gp13.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:CustomVali dator> 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:Validation Summary> 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**********@g eekpedia.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.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.formN ame.txtName.val ue.length == 0)
{
alert("You must enter a name.");
return false;
}
if (document.formN ame.txtPassword .value.length == 0)
{
alert("You must enter a password.");
return false;
}
}

And you need a form tag like:

<form action="file.as px" method="post" name="formName" onSubmit="retur n
LengthCheck()">

Regards,
Andrei

"Sun Jian" <on******@hotma il.com> wrote in message
news:eF******** ******@tk2msftn gp13.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****@NOSPAMd evelop.com> wrote in message
news:60******** **************@ msnews.microsof t.com...
As already mentioned the built in validation controls allow most of what
you're looking for. The <asp:CustomVali dator> 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:Validation Summary> 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
2362
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 any get arounds for this problem apart from the traditional JavaScript?
14
6282
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) show the error message next to the control. For example, if the text field is empty with RequiredField Validator control, it can show the value in...
3
13123
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 how to do this, I created the script to do it and thought I would share it. Its a littel messy but does the job. If anyone has a better solution,...
4
4128
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 JavaScript 'onclick' event for example? 2. Any issues anyone has experienced using client side validation with asp.net forms?
1
5204
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 appear to be the result of double-clicking the submit button on the form. The form has three ASP:Button tags, each of which gets translated into...
1
2501
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 the java script validation as well as the click in code behind? How can this be done ? Can I call the code behind from the javascript function? If...
1
3934
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 the same issue. However, none of the suggested fixes solved my particular problem. I tracked down the cause of the problem, which is related to aspx...
4
2713
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" ControlToValidate="vrg" Text="*" /> <asp:Button ID="Button1" runat="server" Text="go" />
2
3835
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 validation passes, run custom javascript. Or. 2. from my client side javascript to run Validation check and then perform remaining client side...
0
7895
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...
0
7826
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...
0
8182
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. ...
0
8327
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8193
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...
0
3818
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.