开发者

update panel with ClientScriptManager

开发者 https://www.devze.com 2023-03-28 06:25 出处:网络
<asp:button runat=\"server\" id=\"a\" onClick=\"a_Click\"/> code protected void a_Click(object sender, EventArgs e)
<asp:button runat="server" id="a" onClick="a_Click"/>    

code

protected void a_Click(object sender, EventArgs e)
{   
    ClientScriptManager cs = Page.ClientScript;
 开发者_C百科   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


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.


Use ScriptManager.RegisterStartupScript instead of ClientScript.RegisterStartupScript

0

精彩评论

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