UpdatePanel wrapped around a user control

I have a user control that contains some buttons and a placeholder. These buttons force the controls to add / remove from the placeholder. Everything is working fine.

Now I want to put this user control on the page and wrap it in the update panel as follows:

<asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanelFoo" runat="server" UpdateMode="Conditional"> <ContentTemplate> <grid:tablegrid ID="tablegrid_chapters" runat="server" SomeProperty="bar" /> </ContentTemplate> </asp:UpdatePanel> 

When I launch the page, it still does the full postback when I click one of the buttons inside the user control. What am I doing wrong, and how can I fix it?

Update:

 protected void Page_Init() { ScriptManager scr = ScriptManager.GetCurrent(this.Page); Response.Write("EnablePartialRendering: " + scr.EnablePartialRendering); } 

Output "EnablePartialRendering: true"

+4
source share
2 answers

Make sure that on the ScriptManager page on the EnablePartialRendering=true page there is EnablePartialRendering=true .

Update

It looks like your UserControl has no events to look for ... you have 2 options. Move the UpdatePanel inside UserControl.ascx so that it can see button events as children, to tweak or add an event to view, to do this, try something like this:

  public event EventHandler Click; void btn_del_Click(object sender, EventArgs e) { if (NumberOfRowControls > 0) { var rowToWhack = panel_rows.Controls.Children().Single(x => x.ID == "myrow" + (NumberOfRowControls - 1)); panel_rows.Controls.Remove(rowToWhack); NumberOfRowControls--; } if(Click != null) Click(this, e); } void btn_add_Click(object sender, EventArgs e) { var row = NewRow(NumberOfRowControls); panel_rows.Controls.Add(row); if(Click != null) Click(this, e); } 

And update the UpdatePanel to look for it:

 <asp:UpdatePanel ID="UpdatePanelFoo" runat="server" UpdateMode="Conditional"> <ContentTemplate> <grid:tablegrid ID="tablegrid_chapters" runat="server" SomeProperty="bar" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="tablegrid_chapters" EventName="Click"> </Triggers> </asp:UpdatePanel> 
+4
source

Make sure you also add ScriptManager to the page, otherwise there are no UpdatePanel functions.

-one
source

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


All Articles