views:

214

answers:

2

I've been handed a huge Webforms project which I'm trying to understand, and I have a problem where an Update Panel is duplicating a lot of its content. The aspx code for the panel is huge, hundreds of lines long, but it basically looks like this simple example, only with lots more asp:TextBox and asp:ListBox.

<asp:UpdatePanel runat="server" ChildrenAsTriggers="true" RenderMode="Block" UpdateMode="Conditional">
            <ContentTemplate>
                <div><table><tbody><tr><td>
                <label>Search</label><asp:TextBox ID="Search" runat="server"  />
                <asp:LinkButton runat="server" OnClick="find_Click" >Find</asp:LinkButton>
                </td></tr></tbody></table></div>
                <div id="a"><table><tbody><tr><td>
                <label>Result</label><asp:TextBox ID="Result" runat="server" />
                </td></tr></tbody></table></div>       
            </ContentTemplate>
        </asp:UpdatePanel>

and code behind like this.

public void find_Click(Object sender, EventArgs e)
{
    Result.Text = "oranges";
}

When you click the LinkButton, I would expect to see in the result the <div id="a"> section, but with the text 'oranges' in the TextBox. What you actually get is <div id="a"> with 'oranges', followed by the original <div id="a"> with the empty TextBox. The worst bit is that it doesn't do it in this simple example, nor even in a page that I created that had all the original asp:TextBox and asp:ListBox but filled with dummy data. Can anyone point me to any good ways of approaching this problem?

+1  A: 

You might have already tried this, but in the actual problem page, is it possible to remove as many server controls out of the updatepanel and just leave in offending textbox and then see what happens? I'm guessing you'll probably have to comment out alot of .cs/.vb code, which can be a pain.

Also try removing the updatepanel and see what happens.

Steve
Yeah it was a pain :) I ripped it all apart and rebuilt it with a lot less inside the update panel
Colin Pickard
Great, so what, if I might ask, was the problem?
Steve
A: 

Some serious refactoring later, it now looks like (a very bloated version of) this.

<div><table><tbody><tr><td>
<label>Search</label><asp:TextBox ID="Search" runat="server"  />
<asp:LinkButton runat="server" OnClick="find_Click" >Find</asp:LinkButton>
</td></tr></tbody></table></div>
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true" RenderMode="Block" UpdateMode="Conditional">
            <ContentTemplate>
                <div id="a"><table><tbody><tr><td>
                <label>Result</label><asp:TextBox ID="Result" runat="server" />
                </td></tr></tbody></table></div>       
            </ContentTemplate>
        </asp:UpdatePanel>
Colin Pickard