我正在阅读这个JavaScript: Alert.Show(message) From ASP.NET Code-behind
我正在尝试实现相同的功能。所以我创建了一个这样的静态类:
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>";
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
}
}
在这一行:
string script = "<script type="text/javascript">alert('" + cleanMessage + "');</script>";
它显示我的错误:; 预期的
还有
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
错误:找不到类型或命名空间名称“警报”(您是否缺少 using 指令或程序集引用?)
我在这里做错了什么?