views:

258

answers:

2

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 "EnablePartialRendering: true"

+2  A: 

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>
Nick Craver
Woo, making progress. Now it works, one time. I click again and I get a javascript error.
mgroves
@mgroves: What error? We should be able to fix it
Nick Craver
Hmm. Apparently, none. Works like a charm now...
mgroves
@mgroves: Excellent...if you run into another problem just follow-up with a comment
Nick Craver
I will--you've been super helpful, I wish I could give you more points.
mgroves
A: 

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

Nissan Fan