Emech Emech - 2 years ago 116
ASP.NET (C#) Question

Do something javascript before asp.net anypostback

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 () {

It doesn't work... :(

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download