470,836 Members | 1,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,836 developers. It's quick & easy.

Run client side javascript with Validation Control

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 function. So in this case I'll use
<input type="button">.

So far, challenge in case 1 is how to capture validation failure and
limit and stop further client side code execution. I had this code.

Page.ClientScript.GetPostBackEventReference(Button _Search, "") +

where Search() is my client side function, which gets executed with
failed client side validation.

In case 2, I would like to do something like... (I'm doing this with

function Search()
window.top._somevalue = 'xyz';
if (whateverclientvalidationfuctioniscalled()) // client side
validation function name generated by ASP.NET

<input type="button" onclick="Search();">

Any help appreciated.
Oct 21 '08 #1
2 3713
I think you are trying to do what I do. Here is what I do:

In the code-behind:

// Add Submit Confirmation
btnSubmit.Attributes.Add("onClick", "return ConfirmSubmit();");

Then in your aspx page within script tags:

function errorArgs()
this.IsValid = true;
this.errorMsg = "";

function ConfirmSubmit()
var IsValid = true;
var display = "";
var err = new errorArgs();

VerifyVacationDays(err); // Create your validation code in here.

// I have multiple validation routines that I call, but I put it
down to 1 for ease of reading

if (err.IsValid)
return confirm('Are you sure you want to Submit?');
return false;

The key is the "return" in the buttons OnClick event. If it sees
false it will not post back. If it sees true it will.
Oct 21 '08 #2
Thanks for quick response.

So looks like you are calling your own validation functions. I would
like to utilize already generated server-side validation. I just
found my own answer just after posting.


With case 2, where...

if (Page_ClientValidate('SearchValidation')) // that was the function
name I was looking for. SearchValidation is the ValidationGroup name.

and used in server side....

<asp:Button ID="Button_Search" runat="server" Text="Search"
ValidationGroup="SearchValidation" OnClientClick="Search();" />

I'm not sure <asp:Buttonis completely necessary or not here but I'll
move on. Thanks again.
Oct 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lisa Calla | last post: by
3 posts views Thread by Guadala Harry | last post: by
1 post views Thread by Hong Hao | last post: by
3 posts views Thread by David Davis | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.