2010-01-15 4 views
1

WebPart-1.dwp, Webpart-2.dwp 및 WebPart-3.dwp라는 Webpart가 있습니다. 내가는 WebPart-1로드하면 모든 웹 파트가 제대로로드되는하지만는 WebPart-3의 버튼의 클릭 이벤트가 해고되지 않습니다,다른 웹 파트에서 상속을 받으면 클릭 이벤트가 Webparts에서 실행되지 않습니다.

WebPart-1 : WebPart-2 (Inheritance) 
WebPart-2 : WebPArt-3 (Inheritance) 
WebPart-3 : Microsoft.SharePoint.WebPartPages.WebPart (Inheritance) 

:

나는 다음과 같은 시나리오를 가지고있다. 이에

protected override void CreateChildControls() 
{ 
       base.CreateChildControls(); 

       m_MessageLabel = new Label(); 
       m_MessageLabel.ID = "m_MessageLabel"; 
       m_MessageLabel.Text = "Updated the settings successfully. You can now close this WebPart."; 
       m_MessageLabel.Visible = false; 

       m_UpdateButton = new Button(); 
       m_UpdateButton.ID = "m_UpdateButton"; 
       m_UpdateButton.Text = "Update"; 
       m_UpdateButton.CausesValidation = true; 
       m_UpdateButton.ValidationGroup = ValidationGroup; 
       m_UpdateButton.Click += new EventHandler(m_UpdateButton_Click); 
} 

void m_UpdateButton_Click(object sender, EventArgs e) 
{ 
      //Some code here 
} 

protected override void RenderWebPart(HtmlTextWriter output) 
{ 
       base.RenderWebPart(output); 
       m_MessageLabel .RenderControl(output); 
       m_UpdateButton.RenderControl(output); 

} 

어떤 도움을 크게 감지 할 것 : 같은

내는 WebPart-3 코드 보인다.

답변

1

문제는 이벤트 처리기가 너무 늦게 연결될 때까지 연결되지 않는다는 것입니다.

EnsureChildControls를 직접 호출하지 않는 한 CreateChildControls는 렌더링 전에 호출되지 않으며 버튼을 이벤트가 발생시키는 데 너무 늦습니다.

쉬운 솔루션의 OnLoad에 EnsureChildControls를 호출하는 것입니다

+0

I 한 온로드 방법에 다음 코드 : 경우 (! Page.IsPostBack) { EnsureChildControls(); } Page.IsPostback 확인을 삭제 하시겠습니까? – Nagendra

+0

예, 모든 포스트 백마다 이벤트 핸들러를 연결해야합니다. –

관련 문제