导航到新页面并显示警告框 [英] Navigate to a new page and display an alert box

查看:34
本文介绍了导航到新页面并显示警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ASP.Net WebForm 开发应用程序.一旦用户点击一个按钮,应用程序将导航到一个新页面并提示一个对话框欢迎使用 JackiesGame"

I am developing an application by using ASP.Net WebForm. Once user click a button, application will navigate to a new page and prompt out a dialog box "Welcome to JackiesGame"

但是,我能够导航到新页面,但未显示警报对话框.

However, I able to navigate to new page but the alert dialog box does not display.

以下是我的示例代码

void cmdCancel_Click(object sender, EventArgs e)
{
    HttpContext.Current.Response.Redirect(Globals.NavigateURL(TabId), true);
    Page page2 = HttpContext.Current.CurrentHandler as Page;
    ScriptManager.RegisterStartupScript(page2, page2.GetType(), "alertMessage", "alert('Insert Successfully')", true);
}

推荐答案

在第 2 页添加以下内容.在页面加载时,它只会在页面第一次加载脚本时注册.

Add the following in page 2. On the page load it will register only for the first time the page loads the script.

protected void Page_Load(object sender, EventArgs e)
{
   if(!Page.IsPostBack)
   {
    var reg = Request["Welcome"]
       if(reg != null && reg.ToString() == "yes"){
          ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", "alert('Insert Successfully')", true);
      }
   }
}

重定向后的所有代码都将被忽略,因为它必须重定向到新页面.所以代码永远不会被触发.

All code after the redirect is getting ignored since it has to redirect to a new page. So the code never gets triggered.

编辑添加了如何进一步查看的示例

EDIT Added a example of how it can look further

void cmdCancel_Click(object sender, EventArgs e)
{
    string myUrl = Globals.NavigateURL(TabId)+"?Welcome=yes";
    HttpContext.Current.Response.Redirect(myUrl, true);
}

这篇关于导航到新页面并显示警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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