Asp.net网络表单显示警报和重定向

编程入门 行业动态 更新时间:2024-10-11 19:18:34
本文介绍了Asp网络表单显示警报和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前卡住。我有与注册或保存记录的一个按钮一个WebForm。我想是有它显示一个JavaScript警告,然后重定向到一个页面。这里是code我使用

I'm currently stuck. I have a webform with a button that registers or saves a record. What i'd like to is have it display a javascript alert and then redirect to a page. Here is the code i am using

protected void Save(..) { // Do save stuff DisplayAlert("The changes were saved Successfully"); Response.Redirect("Default.aspx"); }

这code只是重定向没有给成功保存的提示。

This code just redirects without giving the prompt Saved Successfully.

下面是我的DisplayAlert code

Here is my DisplayAlert Code

protected virtual void DisplayAlert(string message) { ClientScript.RegisterStartupScript( this.GetType(), Guid.NewGuid().ToString(), string.Format("alert('{0}');", message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")), true ); }

谁能帮我找到一个解决的办法?

Can anyone help me find a solution to this?

感谢

推荐答案

您不能做一个Response.Redirect的,因为你的JavaScript警告将永远不会显示。最好有你的JavaScript code实际上做了 windows.location.href ='Default.aspx的'显示警报后做重定向。事情是这样的:

You can't do a Response.Redirect because your javascript alert will never get displayed. Better to have your javascript code actually do a windows.location.href='default.aspx' to do the redirection after the alert is displayed. Something like this:

protected virtual void DisplayAlert(string message) { ClientScript.RegisterStartupScript( this.GetType(), Guid.NewGuid().ToString(), string.Format("alert('{0}');window.location.href = 'default.aspx'", message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")), true); }

更多推荐

Asp.net网络表单显示警报和重定向

本文发布于:2023-11-27 16:08:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   表单   重定向   网络   Asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!