Solved

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

Posted on 2011-03-10
3
630 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:kravindra
3 Comments
 
LVL 6

Expert Comment

by:Webmonkey
ID: 35095828
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
 
LVL 19

Accepted Solution

by:
Bardobrave earned 500 total points
ID: 35096699
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
 
LVL 8

Expert Comment

by:sriggumma
ID: 35097686
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now