利用delegate调用userControl的方法

 

1 , 在UserControl里定义delegate
    
public   delegate   void  SearchHandle( object  sender, EventArgs e);
    
public   event  SearchHandle SearchEvent;
    protected void btnSearch_ServerClick(object sender, System.EventArgs e)
   {
       if(SearchEvent != null)
       {
          SearchEvent(sender,e);
       }
  }
2 , 在使用UserControl的form里头设置并调用
    
protected  ArtArchives.Web.WebControls.SearchBar Search;
    Search.SearchEvent 
+=   new  ArtArchives.Web.WebControls.SearchBar.SearchHandle(Search_SearchEvent);
    
private   void  Search_SearchEvent( object  sender, EventArgs e)
   {
   }

你可能感兴趣的:(delegate)