Call javascript code afer postback from an update panel

[亡魂溺海] 提交于 2019-12-11 08:26:45

问题


I read tis post

but my problem still there. I try to execute a javascript multiple time on post back, and the script only execute the first time the page load.

To make sure the script is register after each post back i use a guid for the javascript key name.

var xyz = DateTime.Now.ToLongTimeString();
  string script = @"BrokerCustomValue.value='" + CustomValueToBrokerListSerialized + "';alert('" + xyz + "');";
  ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);

I need to precise that my post back event fire after a click on a link button in an update panel. If i put my link butto directly in the page it's working


回答1:


I found the solutions.

When you use an update panel and whant register script, you need to user updatePanel, and updatepanel type in param of the registerstartupscript

like this :

var xyz = DateTime.Now.ToLongTimeString();
  string script = @"BrokerCustomValue.value='" + CustomValueToBrokerListSerialized + "';alert('" + xyz + "');";
  ScriptManager.RegisterStartupScript(_updPanel, _updPanel.GetType(), Guid.NewGuid().ToString(), script, true);


来源:https://stackoverflow.com/questions/1301821/call-javascript-code-afer-postback-from-an-update-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!