我正在阅读这篇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>";
它向我显示错误:;Expected
也是在
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
:未能找到类型或命名空间名称“Alert”(是否缺少using指令或程序集引用?)
我在这里做错了什么?
https://stackoverflow.com/questions/5825165
复制相似问题