Click Click event does not fire on Webparts when inherited from other websites

I have 3 Webpart, namely WebPart-1.dwp, Webpart-2.dwp and WebPart-3.dwp.

I have the following script:

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

If I download WebPart-1, all web parts load correctly, but the button click event on WebPart-3 does not fire.

My WebPart-3 code is as follows:

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);

}

Any help on this will be very noticeable.

+1
source share
1 answer

The problem is that your event handler is not connected until too late.

EnsureChildControls , CreateChildControls , , .

EnsureChildControls OnLoad

+1

Source: https://habr.com/ru/post/1748364/


All Articles