I wanna do something in javascript before page goes for post back.
How to run a javascript function before any asp.net postback?
$('form').submit(function () {
alert('hello');
});
It doesn't work... :(
ASP.NET requires the use of the client-side Javascript, as that's how ASP.NET handles its Events via PostBacks.
How to Raise a Postback from JavaScript? To do this, we need to just call the __doPostBack() function from our javascript code. When the above function is called, it will raise a postback to server.
NET code can do virtually anything when combined with HTML and CSS but JavaScript is still very important and the reason lies in the different domains in which each language operates.
I find the way, in the asp.net forums and it was a some code in codebehind.
Just add this to your Page_Load event handler, changing the javaScript string to what you want to happen.
string scriptKey = "OnSubmitScript";
string javaScript = "alert('RegisterOnSubmitStatement fired');";
this.ClientScript.RegisterOnSubmitStatement(this.GetType(), scriptKey, javaScript);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With