I’m writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event.
Is it possible to call a method I created in ASP with JavaScript’s click event?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, if you don’t want to do it using Ajax or any other way and just want a normal ASP.NET postback to happen, here is how you do it (without using any other libraries):
It is a little tricky though… 🙂
i. In your code file (assuming you are using C# and .NET 2.0 or later) add the following Interface to your Page class to make it look like
ii. This should add (using Tab–Tab) this function to your code file:
iii. In your onclick event in JavaScript, write the following code:
This will call the ‘RaisePostBackEvent’ method in your code file with the ‘eventArgument’ as the ‘argumentString’ you passed from the JavaScript. Now, you can call any other event you like.
P.S: That is ‘underscore-underscore-doPostBack’ … And, there should be no space in that sequence… Somehow the WMD does not allow me to write to underscores followed by a character!