468,115 Members | 2,103 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 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.

Button_Search.Attributes.Add("onclick",
Page.ClientScript.GetPostBackEventReference(Button _Search, "") +
";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
RegisterClientScriptBlock)

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

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

Any help appreciated.
Oct 21 '08 #1
2 3631
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?');
}
else
{
alert(err.errorMsg);
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.

http://forums.asp.net/t/1318892.aspx

With case 2, where...

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

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
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.