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

S

Simon Harvey

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
 
A

alan.washington

In the controls page_load wrap the code in:

if(!IsPostBack) {
//add your code here
}

See if that helps.

Alan Washington
http://www.aewnet.com

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

User submitted from AEWNET (http://www.aewnet.com/)
 
S

Scott Allen

What does the Load event handler look like for the user control?
Is that where you dynamically build the menu elements?
 
S

Simon Harvey

Hi Guys,

You were both right. I realised what was going on shortly after asking for
help.

I took the if(!IsPostback) line out in order to debug something

I'm a twat.

Thanks very much for your help

Kindest Regards

Simon
 
J

Jeffrey Palermo [MCP]

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
 
S

Simon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top