日期:2014-05-18  浏览次数:20439 次

如何在cs文件中弹出提示框???
我是说.cs的文件,不是.aspx.cs的文件,在这里面Response不好用,请问怎样才能弹出提示框呢

------解决方案--------------------
System.Web.HttpContext.Current.Response.Write("<script>alert('sss');</script>");
------解决方案--------------------
C# code

HttpContext.Current.Response.Write("<script>alert('asdaksdjlaksd');location.href=location.href</script>");//要这样子的不?

------解决方案--------------------
给你个类~

C# code
using System;
using System.Text;


public class MessageBox
{
    private MessageBox()
    {
    }

    /// <summary>
    /// 显示消息提示对话框
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="msg">提示信息</param>
    public static void Show(System.Web.UI.Page page, string msg)
    {
        page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
    }

    /// <summary>
    /// 控件点击 消息确认提示框
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="msg">提示信息</param>
    public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
    {
        //Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
        Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
    }

    /// <summary>
    /// 显示消息提示对话框,并进行页面跳转
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="msg">提示信息</param>
    /// <param name="url">跳转的目标URL</param>
    public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
    {
        StringBuilder Builder = new StringBuilder();
        Builder.Append("<script language='javascript' defer>");
        Builder.AppendFormat("alert('{0}');", msg);
        Builder.AppendFormat("location.href='{0}'", url);
        Builder.Append("</script>");
        page.RegisterStartupScript("message", Builder.ToString());

    }

    public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, bool top)
    {
        StringBuilder Builder = new StringBuilder();
        Builder.Append("<script language='javascript' defer>");
        Builder.AppendFormat("alert('{0}');", msg);
        if (top == true)
        {
            Builder.AppendFormat("top.location.href='{0}'", url);
        }
        else
        {
            Builder.AppendFormat("location.href='{0}'", url);
        }
        Builder.Append("</script>");
        page.RegisterStartupScript("message", Builder.ToString());

    }
    /// <summary>
    /// 输出自定义脚本信息
    /// </summary>
    /// <param name="page">当前页面指针,一般为this</param>
    /// <param name="script">输出脚本</param>
    public static void ResponseScript(System.Web.UI.Page page, string script)
    {
        page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
    }

}

------解决方案--------------------
那是因为类里面缺少引用 using System.Web.HttpContext.Current;

或者直接这么写
System.Web.HttpContext.Current.Response.Write("<script>alert('提示');</script>");


------解决方案--------------------
探讨
System.Web.HttpContext.Current.Response.Write(" <script>alert('sss