开发者

ASP.NET AJAX: Creating a postback

I wou开发者_如何学编程ld like to cause a post back that occurs only once by inserting some AJAX into the page after a specific event occurs.

Currently I have:

string script = "<script language='Javascript'>" +
                                    "__doPostBack('GetSpreadsheet', '');" +
                                "</script>";

Page.ClientScript.RegisterStartupScript(this.GetType(), "DownloadExcel", script);

However, after I do this, every post back has an event target of GetSpreadsheet instead of just the first one. What am I doing wrong?


Try using ScriptManager.RegisterStartupScript Method (Control, Type, String, String, Boolean).

In the remarks, you will find this text which explains what you are after.

Startup script blocks that are registered by using this method are sent to the page only when the control that is registering the block is inside an UpdatePanel control that is being updated.


Try checking the IsStartUpScriptRegistered() method before registering your script.

if (!(Page.ClientScript.IsStartupScriptRegistered("DownloadExcel")) )
     Page.ClientScript.RegisterStartupScript(this.GetType(), "DownloadExcel", script);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜