Onload事件未触发警报框 [英] Onload event not firing alert box

查看:102
本文介绍了Onload事件未触发警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有只有gridveiw组件的页面。我想在导航到任何其他链接之前向用户发送警报消息。那是在页面卸载下面是我的代码。但是,页面会导航到相应的页面,但不会提示用户显示警告消息。



Hi I have page which has only gridveiw components. I wanted send a alert message to the user before he navigates to any other link. That is during the page unload below is my code. However the page navigates to the corresponding page but user is not prompted with alert message.

protected override void OnUnload(EventArgs e)
{
    base.OnUnload(e);

    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Have you saved everything');window.open ('TestScriptPages.aspx');", true);

}

推荐答案

使用window.onbeforeunload



use window.onbeforeunload

ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "window.onbeforeunload = function () {if(confirm('Have you saved everything')){window.open ('TestScriptPages.aspx');}}", true);


您好,而不是使用警报使用确认它会询问您的答案确定/取消。



只需尝试以下代码

Hi instead of using alert use confirm it will ask your answer ok/cancel.

Just try this following code
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "if(confirm('Have you saved everything')){window.open ('TestScriptPages.aspx');}", true);


这篇关于Onload事件未触发警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆