How to call a javascript function in the button click event after page validation succeeded(using validation controls) in asp.net

I want to call a javascript function in the button_click event  after page validation succeeded(i.e. I am using validation controls to validate the input fields) in asp.net using c#.

Here I am using validation controls for validation. I don't want use javascript code for validation.

Is't possible to call a javascript function without postback in the button_click event after page validation succeeded?
kravindraAsked:
Who is Participating?
 
BardobraveConnect With a Mentor Commented:
I supose it would be possible to call your server validation through an AJAX call, BUT probably it'll mean to change the clean and easy to code ASP.NET's postback-flow by manual coding.

Once you send your validation to the server through AJAX, the response will come back to the client side without losing contact with the page, and you will be able to call any javascript code you want.

As Webmonkey stated before, if you send your postback to the server, client code is far, far away to your reach. However you'll also able to redirect your page execution to a new response after server validation is passed and there make the client code call, but I'm not very sure that this is what you are asking for.
0
 
WebmonkeyCommented:
Ok... allow me to explain.  The client-side page validation is done with JavaScript (which you say you don't want to use).  The problem is that, if you don't use the client-side validation, then it moves on to server-side validation.  At this point it is too late to call a client-side (javascript) function.

Out of curiousity, why would you not want to use the client-side javascript validation?  When you use it, it doesn't replace the server-side validation - the javascript validation compliments the server-side validation.
0
 
sriggummaCommented:
One thought that immediately strikes me is that:
1. Add a CustomValidator, do not set ControlToValidate property value (Thus, it validates on the Page, but not on a specific control)
2. In the body of ClientValidationFunction, write a code like:  
<script language="javascript">
<!--
function NEWClientValidationFunction(source, args) {
 if (Page_IsValid == true)
 {
   // EXECUTE YOUR JAVASCRIPT FUNCTION
   args.IsValid = true; // This will let continue page further.
 }
}
// -->
</script>

Open in new window


Let us know if you need more help after your try once.

Hope this helps.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.