Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Execute client side script when validation fails - how?

Reply
Thread Tools

Execute client side script when validation fails - how?

 
 
turboJeeper
Guest
Posts: n/a
 
      01-17-2007
I have a form with 16 fields, 10 of which use the
RequiredFieldValidator controls. I want to display a custom message
when the validation fails. However, all the validators have
ClientScript enabled so there is no postback.

What can I hook into on the client side to execute other client side
script (eg. show a hidden label or popup) if validation fails?
 
Reply With Quote
 
 
 
 
turboJeeper
Guest
Posts: n/a
 
      01-18-2007
Can somebody help me out with this please?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      02-01-2007
Sure,

<asp:TextBox runat="server" ID="TextBox1" CausesValidation="false"/>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
ControlToValidate="TextBox1"
ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

<asp:TextBox runat="server" ID="TextBox2" CausesValidation="false"/>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"
ControlToValidate="TextBox2"
ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

<asp:TextBox runat="server" ID="TextBox3" CausesValidation="false"/>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3"
ControlToValidate="TextBox3"
ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

<asp:Button runat="server" ID="Button3" Text="Click!" OnClientClick="return
ValidateUserData();"/>

<script type="text/javascript">
function ValidateUserData()
{
for (i = 0; i < Page_Validators.length; i++)
{
ValidatorValidate(Page_Validators[i]);
}

ValidatorUpdateIsValid();

if (Page_IsValid == true)
{
return true;
}
else
{
alert('my custom code!');
return false;
}
}
</script>

--
Milosz


"turboJeeper" wrote:

> Can somebody help me out with this please?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute client-side code _after_ client-side validation? Bogdan ASP .Net 2 06-09-2008 01:31 PM
Client side script after client side validation with asp.net 2.0 Boss302 ASP .Net 0 11-21-2006 08:43 AM
Using both server side validation and client side validation =?Utf-8?B?dmlkeWE=?= ASP .Net 1 06-02-2005 09:45 PM
Server-side script with input parameter from Client-side script Magnus Blomberg ASP .Net 3 04-14-2005 12:21 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57