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
637 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
[X]
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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending HTML Formatted Email from ASP.NET 2 56
Javascript question 8 44
Change background images after 5 seconds. 12 47
How do you think this website does searches? 5 34
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

738 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