Postback trigger for button inside a usercontrol in Updatepanel

Mahesh KP picture Mahesh KP · May 14, 2012 · Viewed 25.6k times · Source

I have a user control placed inside an update panel, ie like this.

<asp:UpdatePanel ID="testupdatepnl" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
                        <uc1:TestControl ID="ctlTest" runat="server" />
        </ContentTemplate>
</asp:UpdatePanel>

Now i got a button placed inside this user control say Click. I want to postback the whole page on the button click. I tried to add a postback trigger like this

<Triggers>
    <asp:PostBackTrigger ControlID="clickButton" />
</Triggers>

Since the button is inside the usercontrol , i got error while running like this.

Is there any way to do a postback for this button.

Answer

Nalaka526 picture Nalaka526 · May 14, 2012

Remove the <Triggers> from HTML & Add this to PageLoad event

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(WebUserControl11.FindControl("ButtonId")); 

Note : Learned from this