update panel with ClientScriptManager

心不动则不痛 提交于 2019-12-11 18:15:19

问题


<asp:button runat="server" id="a" onClick="a_Click"/>    

code

protected void a_Click(object sender, EventArgs e)
{   
    ClientScriptManager cs = Page.ClientScript;
    string script = "PanelVisiable($('#base')); ";
    script += "$('#message').text(' message  ');";
    script += "$('#message').dialog({modal:true,resizable:false,title:'پیغام',height:80,show:'clip',hide:'explode'});";
    cs.RegisterStartupScript(Page.GetType(), "", script, true);

}

this code work fine


but this

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
  <asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate>
 <asp:button runat="server" id="a" onClick="a_Click"/>
 </ContentTemplate></asp:UpdatePanel>

code

protected void a_Click(object sender, EventArgs e)
{   
    ClientScriptManager cs = Page.ClientScript;
    string script = "PanelVisiable($('#base')); ";
    script += "$('#message').text(' message  ');";
    script += "$('#message').dialog({modal:true,resizable:false,title:'پیغام',height:80,show:'clip',hide:'explode'});";
    cs.RegisterStartupScript(Page.GetType(), "", script, true);

}    

but this script does not work


回答1:


Try using ScriptManager.RegisterStartupScript() method.

See the following MSDN documentation: ScriptManager.RegisterStartupScript()

It states:

Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.




回答2:


Use ScriptManager.RegisterStartupScript instead of ClientScript.RegisterStartupScript



来源:https://stackoverflow.com/questions/7043895/update-panel-with-clientscriptmanager

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