Postback trigger for button inside user control in Updatepanel

I have a user control located inside the update panel, i.e. like this.

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

Now I have a button located inside this user control. Click "Click." I want the page to click the entire page. I tried adding a postback trigger like this

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

Since the button is inside the usercontrol, I got an error while working.

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

+6
source share
3 answers

Remove <Triggers> from the HTML and add this to the PageLoad event

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

Note: From this

+12
source

Since the button that you use as a trigger is placed inside the update panel and after rendering, its client ID changes.

Make the button accessible from the user control and declare a trigger on the server side, for example.

 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. Run the button inside the UpdatePanel using LoginView

0
source

It should also be noted that if you use the Ajax Control Toolkit. You can replace ScriptManager with ToolkitScriptManager.

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

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


All Articles