.net 1.1 LinkButton代码
.net 1.1 LinkButton代码
 using System;
using System; using System.ComponentModel;
using System.ComponentModel; using System.Drawing.Design;
using System.Drawing.Design; using System.Web;
using System.Web; using System.Web.UI;
using System.Web.UI; using System.Web.Util;
using System.Web.Util; using System.Security.Permissions;
using System.Security.Permissions; using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
 namespace JxtLibrary.Controls
namespace JxtLibrary.Controls {
{ public class LinkButton : WebControl, IPostBackEventHandler
    public class LinkButton : WebControl, IPostBackEventHandler {
    { private static readonly object EventClick = new object();
        private static readonly object EventClick = new object(); private static readonly object EventCommand = new object();
        private static readonly object EventCommand = new object();
 [Category("Action")]
        [Category("Action")] public event EventHandler Click
        public event EventHandler Click {
        { add
            add {
            { base.Events.AddHandler(EventClick, value);
                base.Events.AddHandler(EventClick, value); }
            } remove
            remove {
            { base.Events.RemoveHandler(EventClick, value);
                base.Events.RemoveHandler(EventClick, value); }
            } }
        }
 [Category("Action")]
        [Category("Action")] public event CommandEventHandler Command
        public event CommandEventHandler Command {
        { add
            add {
            { base.Events.AddHandler(EventCommand, value);
                base.Events.AddHandler(EventCommand, value); }
            } remove
            remove {
            { base.Events.RemoveHandler(EventCommand, value);
                base.Events.RemoveHandler(EventCommand, value); }
            } }
        }
 public LinkButton()
        public LinkButton() : base(HtmlTextWriterTag.A)
            : base(HtmlTextWriterTag.A) {
        { }
        }
 internal static string GetClientValidatedPostback(Control control)
        internal static string GetClientValidatedPostback(Control control) {
        { string postBackEventReference = control.Page.GetPostBackEventReference(control);
            string postBackEventReference = control.Page.GetPostBackEventReference(control); return ("{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) " + postBackEventReference + "} ");
            return ("{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) " + postBackEventReference + "} "); }
        }

 protected override void AddAttributesToRender(HtmlTextWriter writer)
        protected override void AddAttributesToRender(HtmlTextWriter writer) {
        { if (this.Page != null)
            if (this.Page != null) {
            { this.Page.VerifyRenderingInServerForm(this);
                this.Page.VerifyRenderingInServerForm(this); }
            } base.AddAttributesToRender(writer);
            base.AddAttributesToRender(writer); if (this.Enabled && (this.Page != null))
            if (this.Enabled && (this.Page != null)) {
            { if (this.CausesValidation && (this.Page.Validators.Count > 0))
                if (this.CausesValidation && (this.Page.Validators.Count > 0)) {
                { writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + GetClientValidatedPostback(this));
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + GetClientValidatedPostback(this)); }
                } else
                else {
                { writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Page.GetPostBackClientHyperlink(this, ""));
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Page.GetPostBackClientHyperlink(this, "")); }
                } }
            } }
        }
 protected override void AddParsedSubObject(object obj)
        protected override void AddParsedSubObject(object obj) {
        { if (this.HasControls())
            if (this.HasControls()) {
            { base.AddParsedSubObject(obj);
                base.AddParsedSubObject(obj); }
            } else if (obj is LiteralControl)
            else if (obj is LiteralControl) {
            { this.Text = ((LiteralControl)obj).Text;
                this.Text = ((LiteralControl)obj).Text; }
            } else
            else {
            { string text = this.Text;
                string text = this.Text; if (text.Length != 0)
                if (text.Length != 0) {
                { this.Text = string.Empty;
                    this.Text = string.Empty; base.AddParsedSubObject(new LiteralControl(text));
                    base.AddParsedSubObject(new LiteralControl(text)); }
                } base.AddParsedSubObject(obj);
                base.AddParsedSubObject(obj); }
            } }
        }
 protected override void LoadViewState(object savedState)
        protected override void LoadViewState(object savedState) {
        { if (savedState != null)
            if (savedState != null) {
            { base.LoadViewState(savedState);
                base.LoadViewState(savedState); string str = (string)this.ViewState["Text"];
                string str = (string)this.ViewState["Text"]; if (str != null)
                if (str != null) {
                { this.Text = str;
                    this.Text = str; }
                } }
            } }
        }
 protected virtual void OnClick(EventArgs e)
        protected virtual void OnClick(EventArgs e) {
        { EventHandler handler = (EventHandler)base.Events[EventClick];
            EventHandler handler = (EventHandler)base.Events[EventClick]; if (handler != null)
            if (handler != null) {
            { handler(this, e);
                handler(this, e); }
            } }
        }
 protected virtual void OnCommand(CommandEventArgs e)
        protected virtual void OnCommand(CommandEventArgs e) {
        { CommandEventHandler handler = (CommandEventHandler)base.Events[EventCommand];
            CommandEventHandler handler = (CommandEventHandler)base.Events[EventCommand]; if (handler != null)
            if (handler != null) {
            { handler(this, e);
                handler(this, e); }
            } base.RaiseBubbleEvent(this, e);
            base.RaiseBubbleEvent(this, e); }
        }
 protected override void OnPreRender(EventArgs e)
        protected override void OnPreRender(EventArgs e) {
        { base.OnPreRender(e);
            base.OnPreRender(e); if ((this.Page != null) && this.Enabled)
            if ((this.Page != null) && this.Enabled) {
            { //this.Page.RegisterPostBackScript();
                //this.Page.RegisterPostBackScript(); }
            } }
        }
 protected override void RenderContents(HtmlTextWriter writer)
        protected override void RenderContents(HtmlTextWriter writer) {
        { if (this.HasControls())
            if (this.HasControls()) {
            { base.RenderContents(writer);
                base.RenderContents(writer); }
            } else
            else {
            { writer.Write(this.Text);
                writer.Write(this.Text); }
            } }
        }
 void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) {
        { if (this.CausesValidation)
            if (this.CausesValidation) {
            { this.Page.Validate();
                this.Page.Validate(); }
            } this.OnClick(new EventArgs());
            this.OnClick(new EventArgs()); this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument));
            this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument)); }
        }
 [Category("Behavior"), Bindable(false), DefaultValue(true)]
        [Category("Behavior"), Bindable(false), DefaultValue(true)] public bool CausesValidation
        public bool CausesValidation {
        { get
            get {
            { object b = ViewState["CausesValidation"];
                object b = ViewState["CausesValidation"]; return ((b == null) ? true : (bool)b);
                return ((b == null) ? true : (bool)b); }
            } set
            set {
            { ViewState["CausesValidation"] = value;
                ViewState["CausesValidation"] = value; }
            } }
        }
 [Bindable(true), Category("Behavior"), DefaultValue("")]
        [Bindable(true), Category("Behavior"), DefaultValue("")] public string CommandArgument
        public string CommandArgument {
        { get
            get {
            { string s = (string)ViewState["CommandArgument"];
                string s = (string)ViewState["CommandArgument"]; return ((s == null) ? String.Empty : s);
                return ((s == null) ? String.Empty : s); }
            } set
            set {
            { ViewState["CommandArgument"] = value;
                ViewState["CommandArgument"] = value; }
            } }
        }
 [Category("Behavior"), DefaultValue("")]
        [Category("Behavior"), DefaultValue("")] public string CommandName
        public string CommandName {
        { get
            get {
            { string s = (string)ViewState["CommandName"];
                string s = (string)ViewState["CommandName"]; return ((s == null) ? String.Empty : s);
                return ((s == null) ? String.Empty : s); }
            } set
            set {
            { ViewState["CommandName"] = value;
                ViewState["CommandName"] = value; }
            } }
        }
 [PersistenceMode(PersistenceMode.InnerDefaultProperty), Bindable(true), Category("Appearance"), DefaultValue("")]
        [PersistenceMode(PersistenceMode.InnerDefaultProperty), Bindable(true), Category("Appearance"), DefaultValue("")] public virtual string Text
        public virtual string Text {
        { get
            get {
            { object o = ViewState["Text"];
                object o = ViewState["Text"]; return ((o == null) ? String.Empty : (string)o);
                return ((o == null) ? String.Empty : (string)o); }
            } set
            set {
            { if (HasControls())
                if (HasControls()) {
                { Controls.Clear();
                    Controls.Clear(); }
                } ViewState["Text"] = value;
                ViewState["Text"] = value; }
            } }
        } }
    } }
}



 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号