开发者

UpdatePanel wrapped around a user control

开发者 https://www.devze.com 2022-12-18 05:13 出处:网络
I have a user control which contains some buttons and a placeholder.Those buttons cause controls to be added/removed from placeholder.Everything works fine.

I have a user control which contains some buttons and a placeholder. Those buttons cause controls to be added/removed from placeholder. Everything works fine.

Now I want to put this user control in a page, and wrap it in an updatepanel like so:

            <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 run the page, it's still doing a full postback when I hit one of the buttons inside the user control. What am I doing wrong, and how can I remedy this?

Update:

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

Outputs "Enabl开发者_如何学GoePartialRendering: true"


Make sure you have EnablePartialRendering=true on your ScriptManager in the page.

Update

It looks like your UserControl has no events to be looking for...you have 2 options here. Move the UpdatePanel inside the UserControl .ascx so it can see the button events as children to rig up or add an event for it to see, to do that 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 be looking 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>


Make sure you add a ScriptManager as well to the page, otherwise there's no UpdatePanel functionality.

0

精彩评论

暂无评论...
验证码 换一张
取 消