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
629 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now