簡體   English   中英

如何通過事件從UserControl背后的代碼中觸發JS

[英]How to fire JS from code behind of a UserControl by an event

在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頁面本身是“ prettyPhoto”彈出窗口。

可能有以下可能的原因嘗試更改這些內容並檢查其是否有效

 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM