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

这个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