2010-12-01 14 views

答えて

0

はい。コントロールにパブリックイベントを追加します。イベントに添付されたデリゲートを探すメソッドを追加します。代理人がいる場合は、イベントを発生させます。ユーザーコントロールで

:ここでは例です

public partial class Controls_UserComments : System.Web.UI.UserControl 
{ 
    // the event delegates may listen for 
    public event EventHandler CommentEditing; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
    // handle an event in the user control and bubble the event up to any delegates 
     GridView_Comments.RowCancelingEdit += new GridViewCancelEditEventHandler(GridView_Comments_RowCancelingEdit); 
    } 

    void GridView_Comments_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 
    { 
     GridView_Comments.EditIndex = -1; 
     GridView_Comments.DataBind(); 

     // raise the event for attached delegates 
     if (CommentEditing != null) 
      CommentEditing(this, EventArgs.Empty); 
    } 
} 

、ユーザーコントロールを利用したWebフォームで:

<ppc:UserComments ID="UserComments_ObservationComments" runat="server" 
    OnCommentEditing="RefreshComments" 
    /> 

幸運!

+0

ありがとうございました – Gerard

関連する問題