当前位置: 代码迷 >> ASP.NET >> 这个messagebox类应该如何使用
  详细解决方案

这个messagebox类应该如何使用

热度:745   发布时间:2013-02-25 00:00:00.0
这个messagebox类应该怎么使用?
在vs2008中具体做web页面应该怎么使用呢?


C# code
using System;using System.Web.UI;using System.Text;/// <summary>/// MessageBox 的摘要说明。/// </summary>public class MessageBox{    public MessageBox()    {        //        // TODO: 在此处添加构造函数逻辑        //    }    /// <summary>    /// 消息提示    /// 调用方法:  MessageBox.Show(Page, this, "是否可以呢!");    /// </summary>    /// <param name="page0">参数:Page </param>    /// <param name="this0">参数:this </param>    /// <param name="str">参数:显示文本内容 </param>    public static void Show(Page page0,Page this0, string str)    {        StringBuilder sb = new StringBuilder("");        sb.Append("alert('" + str + "');");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "Show"))        {            cs.RegisterStartupScript(this0.GetType(), "Show", sb.ToString(), true);        }    }        /// <summary>    /// 打开新页面    /// </summary>    /// <param name="page0">参数:Page</param>    /// <param name="this0">参数:this</param>    /// <param name="url">参数:新页面地址</param>    /// <param name="target">打开页面的方式</param>    public static void OpenUrl(Page page0, Page this0, string url, string target)    {        StringBuilder sb = new StringBuilder("");        sb.Append("window.open('" + url + "','" + target + "');");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "OpenUrl"))        {            cs.RegisterStartupScript(this0.GetType(), "OpenUrl", sb.ToString(), true);        }           }    /// <summary>    /// 弹出消息提示,并且打开新页面    /// </summary>    /// <param name="page0">参数:Page</param>    /// <param name="this0">参数:this</param>    /// <param name="str">参数:消息提示文本内容</param>    /// <param name="url">参数:新页面地址</param>    public static void ShowUrl(Page page0, Page this0, string str, string url)    {        StringBuilder sb = new StringBuilder("");        sb.Append("alert('" + str + "');");        sb.Append("document.location.href='" + url + "';");            ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "ShowUrl"))        {            cs.RegisterStartupScript(this0.GetType(), "ShowUrl", sb.ToString(), true);        }     }    /// <summary>    /// 非模态显示    /// </summary>    /// <param name="page0"></param>    /// <param name="this0"></param>    /// <param name="url"></param>    /// <param name="width"></param>    /// <param name="height"></param>    public static void Show(Page page0, Page this0, string url,int width, int height)    {        //strreturnval=window.showModalDialog('../Public/Pub_SpxxView.aspx','window','dialogWidth=500px;dialogHeight=410px');           //window.document.all("allvalue").value = strreturnval;        StringBuilder sb = new StringBuilder("");        sb.Append("ReturnValue = window.showModelessDialog('" + url + "', window ,'dialogWidth=" + width.ToString() + "px;dialogHeight=" + height.ToString() + "px');");        sb.Append("");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "ShowDialog"))        {            cs.RegisterStartupScript(this0.GetType(), "ShowDialog", sb.ToString(), true);        }     }    /// <summary>    /// 模态显示    /// </summary>    /// <param name="page0"></param>    /// <param name="this0"></param>    /// <param name="url"></param>    /// <param name="width"></param>    /// <param name="height"></param>    public static void ShowDialog(Page page0, Page this0, string url,int width, int height)    {        //strreturnval=window.showModalDialog('../Public/Pub_SpxxView.aspx','window','dialogWidth=500px;dialogHeight=410px');           //window.document.all("allvalue").value = strreturnval;        StringBuilder sb = new StringBuilder("");        sb.Append("ReturnValue = window.showModalDialog('" + url + "', window ,'dialogWidth="+width.ToString()+"px;dialogHeight="+height.ToString()+"px');");        sb.Append("");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "ShowDialog"))        {            cs.RegisterStartupScript(this0.GetType(), "ShowDialog", sb.ToString(), true);        }     }    /// <summary>    /// 打开新页面    /// </summary>    /// <param name="page0">参数:Page</param>    /// <param name="this0">参数:this</param>    /// <param name="url">参数:新页面地址</param>    public static void Redirect(Page page0, Page this0, string url)    {        StringBuilder sb = new StringBuilder("");        sb.Append("window.open('" + url + "','right');");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "Redirect"))        {            cs.RegisterStartupScript(this0.GetType(), "Redirect", sb.ToString(), true);        }    }    /// <summary>    /// 关闭页面窗口    ///一般应用于服务器控件事件代码中,之前可执行其他代码;    /// </summary>    /// <param name="page0">参数:Page</param>    /// <param name="this0">参数:this</param>    public static void WinClose(Page page0,Page this0)    {        StringBuilder sb = new StringBuilder("");                sb.Append(" window.dialogArguments.location.href =window.dialogArguments.location.href;");        sb.Append(" window.close();");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "WinClose"))        {            cs.RegisterStartupScript(this0.GetType(), "WinClose", sb.ToString(), true);        }        //this.Page.RegisterStartupScript("script", "<script>alert('添加成功');window.location.href=window.location.href</script>");    }    /// <summary>    /// 关闭页面窗口    ///一般应用于服务器控件事件代码中,之前可执行其他代码;    /// </summary>    /// <param name="page0">参数:Page</param>    /// <param name="this0">参数:this</param>    /// <param name="str">参数:返回值</param>    public static void WinClose(Page page0, Page this0, string str)    {        StringBuilder sb = new StringBuilder("");        sb.Append("window.returnValue = '" + str + "';");        sb.Append("window.close();");        ClientScriptManager cs = page0.ClientScript;        if (!cs.IsStartupScriptRegistered(this0.GetType(), "WinClose1"))        {            cs.RegisterStartupScript(this0.GetType(), "WinClose1", sb.ToString(), true);        }            }}
  相关解决方案