开发者

CustomControl (Dropdownlist) in asp.net

开发者 https://www.devze.com 2022-12-22 02:00 出处:网络
how to write events using delegates in customcontrol开发者_如何学Go(Dropsownlist)Here is sample using event in custom control:

how to write events using delegates in customcontrol开发者_如何学Go(Dropsownlist)


Here is sample using event in custom control:

  using System;
  using System.Web.UI;

  namespace CustomControls 
  {  
     public class MyButton: Control, IPostBackEventHandler 
     {     
        // Defines the Click event.
        public event EventHandler Click;

        // OnClick dispatches the event to delegates that
        // are registered with the Click event.
        // Controls that derive from MyButton can handle the
        // Click event by overriding OnClick
        // instead of attaching a delegate. The event data
        // is passed as an argument to this method.
        protected virtual void OnClick(EventArgs e) 
        {     
           if (Click != null) 
           {
              Click(this, e);
           }  
        }

        // Method of IPostBackEventHandler that raises change events.
        public void RaisePostBackEvent(string eventArgument)
        {     
           OnClick(EventArgs.Empty);
        }

        protected override void Render(HtmlTextWriter output) 
        {     
           output.Write("<INPUT TYPE = submit name = " + this.UniqueID + 
              " Value = 'Click Me' />"); 
        }
     }    
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消