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

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

问题描述

我正在使用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天全站免登陆