使用ClientScriptManager更新面板 [英] update panel with ClientScriptManager
本文介绍了使用ClientScriptManager更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:button runat="server" id="a" onClick="a_Click"/>
代码
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);
}
此代码可以正常工作
但是这个
<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>
代码
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);
}
但是此脚本不起作用
推荐答案
尝试使用ScriptManager.RegisterStartupScript()
方法.
请参阅以下MSDN文档: ScriptManager.RegisterStartupScript()
See the following MSDN documentation: ScriptManager.RegisterStartupScript()
它说明:
为内部的控件注册启动脚本块 通过使用ScriptManager控件更新面板,并添加脚本 阻止页面.
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.
这篇关于使用ClientScriptManager更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文