9
votes

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.

3
@Nalaka526: thanks , i'll check it.. - Mahesh KP
@Nalaka526 : but i got an error like 'A control with ID 'ctl00$phContent$ctlList$ctlClientLocations$clickButton' could not be found for the trigger in UpdatePanel 'testupdatepnl'." - Mahesh KP
Can you please send the code you have modified i.e. assigning control's UniqueID serverside as trigger - Imran Rizvi

3 Answers

16
votes

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

0
votes

Because button you are using as trigger is placed inside update panel and after render its client id gets changed.

Make the button accessable from user control and declare the trigger at server side e.g.

var ClickButton= ctlTest.FindControl("clickButton") as Button;


var trigger = new PostBackTrigger();
trigger.ControlID = ClickButton.UniqueID.ToString();
testupdatepnl.Triggers.Add(trigger);

See the following thread for more details Trigger a button inside a UpdatePanel with a LoginView

0
votes

You should also note that if you are using Ajax Control Toolkit. You can replace ScriptManager to ToolkitScriptManager.

Dim btn As Button = CType(UserControl.FindControl("ButtonID"), Button)        
AjaxControlToolkit.ToolkitScriptManager.GetCurrent(Page).RegisterPostBackControl(btn)