我正在尝试触发如下所示的弹出窗口,但它不起作用。请帮忙
public void btnSubmit_Click(Object o, EventArgs e)
{
if (checkFileExists(Convert.ToString(fileInfo)))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Msg", "<script type=\"text/javascript\" language=\"javascript\">function showMsg(){return confirm(\"This image name already exists, do you want to replace it?\");}</script>", true);
btnSubmit.OnClientClick = "return showMsg()";
}
if (something else)
{
// It does whatever is here but never pops the question above
}
}
在我的按钮上
<asp:Button class="Button" ID="btnSubmit" CausesValidation="True" Text="SUBMIT" runat="server"
OnClick="btnSubmit_Click"></asp:Button>
最佳答案
Page.ClientScript.RegisterClientScriptBlock 不工作的另一个原因是页面没有服务器端表单,例如<form id="form1" runat="server">... </form>
关于c# - 使用 Page.ClientScript.RegisterClientScriptBlock 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6538640/