导航到新页面并显示警告框

Navigate to a new page and display an alert box(导航到新页面并显示警告框)
本文介绍了导航到新页面并显示警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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);
}

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)