asp.net服务器组件开发给System.Web.UI.WebControls.Label增加单击事件

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。

 

asp.net服务器组件开发给System.Web.UI.WebControls.Label增加单击事件

还有一个类是给Edit增加服务端可以相应的OnBlur事件

 

    public class ClickableLabel : Label, IPostBackEventHandler
    {
        public event EventHandler Click;

        protected void onClick(EventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }

        //When postback is caused by this control, raise the event
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            onClick(new EventArgs());
        }

        //Add onclick attribute to cause a postback when Label is clicked
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.GetPostBackEventReference(this, "onClick"));
        }
    }
    public class MyTextBox : TextBox, IPostBackEventHandler
    {
        public event EventHandler Blur;
        protected void OnBlur(EventArgs e)
        {
            if (Blur != null)
            {
                Blur(this, e);
            }
        }

        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            postBackEvent(eventArgument);
        }

        private void postBackEvent(string argument)
        {
            switch (argument)
            {
                case "onblur":
                    OnBlur(new EventArgs());
                    break;
            }
        }

        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute("onblur", Page.ClientScript.GetPostBackEventReference(this, "onblur"));
        }

    }

你可能感兴趣的:(String,服务器,Class,asp.net,textbox,PostBack)