2010-03-04 82 views
2

如何编写使用委托在customcontrol事件(Dropsownlist)CustomControl(下拉列表)在asp.net

+2

您可能要加点详细关于你已经尝试了什么,什么没有工作等等。社区不在这里为你写代码。 – 2010-03-04 12:15:47

回答

0

下面是使用自定义的控制事件样本:

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' />"); 
     } 
    }  
    }