如何通过事件从UserControl的代码中触发JS [英] How to fire JS from code behind of a UserControl by an event
本文介绍了如何通过事件从UserControl的代码中触发JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ASP.NET C#中,我想从UserControl的代码隐藏中显示ALERT('HI')但不起作用:
In ASP.NET C#, I want to show an ALERT('HI') from codebehind of a UserControl but doesn't work:
用户控制:
<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的弹出窗口。
Forgot to say that the ASP.NET page itself is pop-out window by "prettyPhoto".
推荐答案
可能有以下可能的原因尝试更改这些并检查它是否有效
there may be below possible reasons try to change these and check it works or not
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);
这篇关于如何通过事件从UserControl的代码中触发JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文