在ASP.NET C#中,我想从UserControl的代码隐藏中显示ALERT(' HI'),但不起作用:
用户控制:
<asp:UpdatePanel ID="updatepanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click();"/>
</ContentTemplate>
</asp:UpdatePanel>
ASP.NET页面
protected void btnSubmit_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "s1", "javascript:alert('hi!')", true);
}
更新
忘了说ASP.NET页面本身是&#34; prettyPhoto&#34;的弹出窗口。
答案 0 :(得分:5)
可能有以下可能的原因尝试更改这些并检查它是否有效
1). ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('hi!')", true);//no need to use javascript with alert when bool set to true
2). ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('hi!')", true);
3). ClientScript.RegisterClientScriptBlock(GetType(), "sas", "<script> alert('hi!');</script>", true);