Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
632 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

808 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