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


基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01