all groups > asp.net building controls > october 2004 >
You're in the

asp.net building controls

group:

Each time I do a postback, another copy of a control is added to the page!


Re: Each time I do a postback, another copy of a control is added to the page! Scott Allen
10/22/2004 10:52:57 AM
asp.net building controls:
What does the Load event handler look like for the user control?
Is that where you dynamically build the menu elements?
--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 22 Oct 2004 14:40:34 +0100, "Simon Harvey"
[quoted text, click to view]
Each time I do a postback, another copy of a control is added to the page! Simon Harvey
10/22/2004 2:40:34 PM
Hi everyone,

I'm having a really weird problem with one of my pages. Whenever I hit the
submit button, it reloads the page but another side menu control appears
underneath the original one. This will occur as many times as I hit the
submit button. The thing that I don't understand is that I'm *not* adding
the controls dynamically. The html for the page is very very simple and is
basically the following without the body/head tags etc:

<table width="85%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="151" valign="top">
<uc1:sidemenucontrol id="SideMenuControl1"
runat="server"></uc1:sidemenucontrol>
</td>
<td>
<uc1:UserRolesControl id="UserRolesControl1"
runat="server"></uc1:UserRolesControl>
</td>
</tr>
</table>

The control that is repeating itself is the SideMenuControl. I don't know
why because it just displays menu elements. Admittedly those elements are
added dynamically but it seems to be that the whole menu is being added each
time, leading me to believe that the problem lies with the (very simple)
containing page.

Can anyone help with this?

I' would be very greatful for any help

Thanks

Simon

Re: Each time I do a postback, another copy of a control is added to the page! Jeffrey Palermo [MCP]
10/22/2004 11:41:36 PM
Simon,
If this is a user control that you consume only and don't want to mess
with the code, try disabling its viewstate. That's probably the issue. Or
if this is your user control, wrap the Load logic in a test for
Page.IsPostBack

Best regards,
Jeffrey Palermo

[quoted text, click to view]

Re: Each time I do a postback, another copy of a control is added to the page! Simon
10/23/2004 4:45:22 PM
Thanks guys. I was just being very stupid.

I took the if !IsPostBack line out in order to debug something else. Forgot
to put it back in.

I'll remember the symptoms of that particular mistake. It wasnt something
I'd ever seen before.

Very odd

:-)

Simon

AddThis Social Bookmark Button