获取 confirm 点击事件【自定义控件】

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

/*------------------------------------------------------------------------------------
 * 文件名:MessageBox.cs

 * 文件功能描述:Excel的导入导出
 *
 * 创建标识:刘佳忻     20081128
 *
 * 修改标识:
 * 修改描述:
 *
* ----------------------------------------------------------------------------------*/

namespace I799NET
{
 
   [Serializable, DesignTimeVisible, ToolboxData("<{0}:MessageBox runat=\"server\">")]
public class MessageBox : WebControl
{
    // Fields
    private const string cancel = "cancel";//"cancel";
    private string content;
    private string m_Session = "msgSession";
    private const string notPressed = "notPressed";
    private const string ok = "ok";//"ok";

    // Events
    public event Message GetMessageBoxResponse;

    // Methods
    public void Alert(string message)
    {
        string str = message.Replace("\n", @"\n");
        str = message.Replace("\"", "'");
        StringBuilder builder = new StringBuilder(50);
        builder.Append("");
        this.content = builder.ToString();
    }

    public void Confirm(string message)
    {
        this.Confirm(message, null);
    }

    public void Confirm(string message, object data)
    {
        string str = message.Replace("\n", @"\n");
        str = message.Replace("\"", "'");
        StringBuilder builder = new StringBuilder(100);
        builder.AppendFormat("", "notPressed");
        builder.Append("");
        this.content = builder.ToString();
        if (data != null)
        {
            this.Page.Session[this.m_Session + this.ClientID] = data;
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        object data = null;
        string str = this.Page.Request.Form[this.HiddenFieldName];
        if (str != null)
        {
            if (!(str == "ok"))
            {
                if (str == "cancel")
                {
                    this.Page.Request.Form[this.HiddenFieldName].Replace("cancel", "notPressed");
                    if (this.Page.Session[this.m_Session + this.ClientID] != null)
                    {
                        data = this.Page.Session[this.m_Session + this.ClientID];
                        this.Page.Session.Remove(this.m_Session + this.ClientID);
                    }
                    this.OnMessageBoxShow(new MessageBoxEventHandler(MessageBoxEventHandler.Button.Cancel, data));
                }
                else if (str == "notPressed")
                {
                }
            }
            else
            {
                this.Page.Request.Form[this.HiddenFieldName].Replace("ok", "notPressed");
                if (this.Page.Session[this.m_Session + this.ClientID] != null)
                {
                    data = this.Page.Session[this.m_Session + this.ClientID];
                    this.Page.Session.Remove(this.m_Session + this.ClientID);
                }
                this.OnMessageBoxShow(new MessageBoxEventHandler(MessageBoxEventHandler.Button.Ok, data));
            }
        }
        base.OnLoad(e);
    }

    protected virtual void OnMessageBoxShow(MessageBoxEventHandler e)
    {
        if (this.GetMessageBoxResponse != null)
        {
            this.GetMessageBoxResponse(this, e);
        }
    }

    protected override void Render(HtmlTextWriter output)
    {
        if (!base.DesignMode)
        {
            output.Write(this.content);
        }
        else
        {
            Label label = new Label();
            label.Font.Bold = this.Font.Bold;
            label.Font.Italic = this.Font.Italic;
            label.Font.Names = this.Font.Names;
            label.Font.Overline = this.Font.Overline;
            label.Font.Size = this.Font.Size;
            label.Font.Strikeout = this.Font.Strikeout;
            label.Font.Underline = this.Font.Underline;
            label.ForeColor = this.ForeColor;
            label.BackColor = this.BackColor;
            label.BorderColor = this.BorderColor;
            label.BorderStyle = this.BorderStyle;
            label.BorderWidth = this.BorderWidth;
            label.Text = this.ID;
            label.RenderControl(output);
        }
    }

    // Properties
    private string HiddenFieldName
    {
        get
        {
            return ("hidF" + this.ID);
        }
    }

    // Nested Types
    public delegate void Message(object sender, MessageBox.MessageBoxEventHandler e);

    public class MessageBoxEventHandler : EventArgs
    {
        // Fields
        public readonly Button ButtonPressed;
        public readonly object Data;

        // Methods
        public MessageBoxEventHandler(Button buttonPressed) : this(buttonPressed, null)
        {
        }

        public MessageBoxEventHandler(Button buttonPressed, object data)
        {
            this.ButtonPressed = buttonPressed;
            this.Data = data;
        }

        // Nested Types
        public enum Button
        {
            Ok,
            Cancel,
            NotPressed
        }
    }
}

 
 
 

}

 
 
 

 

转载于:https://www.cnblogs.com/i799/archive/2008/11/29/1343769.html

你可能感兴趣的:(获取 confirm 点击事件【自定义控件】)