我正在阅读这个JavaScript:Alert.Show(消息)来自ASP.NET代码隐藏
我正在努力实现同样的目标.所以我创建了一个这样的静态类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Text;
using System.Web.UI;
namespace Registration.DataAccess
{
public static class Repository
{
/// <summary>
/// Shows a client-side JavaScript alert in the browser.
/// </summary>
/// <param name="message">The message to appear in the alert.</param>
public static void Show(string message)
{
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\'");
string script = "<script type="text/javascript">alert('" + cleanMessage + "');</script>"; …Run Code Online (Sandbox Code Playgroud) 我现在卡住了.我有一个带有按钮的webform,可以注册或保存记录.我想要的是让它显示一个javascript警报,然后重定向到一个页面.这是我正在使用的代码
protected void Save(..)
{
// Do save stuff
DisplayAlert("The changes were saved Successfully");
Response.Redirect("Default.aspx");
}
Run Code Online (Sandbox Code Playgroud)
此代码只是重定向而不提示提示已成功保存.
这是我的DisplayAlert代码
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
);
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我找到解决方案吗?
谢谢