2010-03-04 119 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' />"); 
     } 
    }  
    }