Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wish to execute a javascript function after asp.net postback with out using ajax.

I've tried the following in my even method with no luck:

Page.ClientScript.RegisterStartupScript(GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
341 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should rather use the ScriptManager class, since the Page.ClientScript property is deprecated...

The ClientScriptManager class is new in ASP.NET 2.0 and replaces Page class methods for managing scripts that are now deprecated.
Reference: MSDN - Page.ClientScript Property

The advantage with ScriptManager is that it works with asynchronous postbacks, so if you are using AJAX it will not work with the ClientScriptManager.

Your code would look like this:

ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

Note also that if you are using AJAX and have a piece of javascript code, that you want executed on multiple postbacks, then you should refer to your UpdatePanel in the firstargument e.g.:

ScriptManager.RegisterStartupScript(MainUpdatePanel, typeof(string), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...