一个比较实用的服务器端模拟客户端Alert的代码

public class Alert
{
    public Alert()
    {
       
    }

    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;

        // Check 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);
        }
    }

    public static void Show()
    {
        throw new Exception("The method or operation is not implemented.");
    }
}

原文地址:https://www.cnblogs.com/Koy/p/1228332.html