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);
}
这篇关于导航到新页面并显示警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:导航到新页面并显示警告框


基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01