【发布时间】:2017-10-17 11:06:13
【问题描述】:
问题详情:
在数据库中保存数据后,我需要向用户显示警报。 为此,我从代码隐藏中注册了脚本。 但它不适用于更新面板,而它在没有更新面板的情况下按预期工作。 我需要让它与更新面板一起工作。
我尝试在注册脚本时添加$(document).ready(function (),但没有成功。
然后,我尝试使用ScriptManager.RegisterClientScriptBlock() 方法而不是Page.ClientScript.RegisterStartupScript(),但它也不起作用。
这是网页(ASPX)的代码sn-p:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Button ID="btnOutsideUpdatePanel" runat="server" Text="Outside UpdatePanel" OnClick="btnOutsideUpdatePanel_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnInsideUpdatePanel" runat="server" Text="Inside UpdatePanel" OnClick="btnInsideUpdatePanel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<uc1:Child runat="server" id="Child1" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<uc1:Child runat="server" id="Child2" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
这里是用户控制(ASCX)的代码sn-p:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Child.ascx.cs" Inherits="UpdatePanelAndScript.Child" %>
<asp:Button ID="btnUserControl" runat="server" Text="User Control" OnClick="btnUserControl_Click" />
网页代码隐藏:
protected void btnOutsideUpdatePanel_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowSuccess", "alert('Hi');", true);
}
protected void btnInsideUpdatePanel_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowSuccess", "alert('Hi');", true);
}
用户控件的代码隐藏:
protected void btnUserControl_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowSuccess", "alert('Hi');", true);
}
【问题讨论】:
标签: asp.net user-controls updatepanel scriptmanager registerclientscriptblock