The issue was that Page_Load was firing twice. Someone in
another
group solved this by suggesting I put the following in my
ASPX page
declaration, which worked perfectly:
<% Page language="VB"
AutoEventWireup="false" %>
Also I could have removed the "Handles
MyBase.Load" from my Page_Load,
but the above method is better coding practice.
The problem everyone had recreating this issue is because no
one was
simply copying the code I posted into an ASPX page and
trying to run
it (although I was pretty clear about that). Visual Studio
has the
AutoEventWireup automatically set to False by default (which
I didn't
know until now), so anyone running my code in VS wouldn't
have the
same problem unless they explicitly designated
AutoEventWireup to be
True.
On Mar 7, 10:46 am, "Robert Speake"
<bspe... suddenlink.net> wrote:
> I used your code verbatim and only got one button on my
form. I am using
> Visual Web Developer 2005 Express Edition (.NET 2.0).
For some reason your
> Page_Load is firing twice.
>
> If you are intent on using this approach, you should
add some code that
> first checks to see if the form's control collection
contains a button with
> the ID you are planning to use.
>
>
>
>
>
> -----Original Message-----
> From: aspnet googlegroups.com [mailto:aspnet googlegroups.com] On Behalf Of
>
> Buddy Z
> Sent: Wednesday, March 07, 2007 9:13 AM
> To: ASP.Net Community
> Subject: [asp.net:2491] Re: ASP.NET: programmatically
adding a button adds 2
> buttons? help
>
> Nope. Two buttons on inital load. Not dealing with
refreshes or PostBack or
> any of that.
>
> Can anyone tell me they used my exact code and only 1
button displays?
> Because I've tested it on 2 completely different
servers in 2 different time
> zones and get the same result.
>
> On Mar 7, 12:37 am, ajit dhaliwal <aju_dhali... yahoo.com> wrote:
> > i think when u will refresh the page a new buton
will be created , so
> > create Object in class level and add it in New
method......or check
> > PostBack Property
>
> > ----- Original Message ----
> > From: Buddy Z <bud... gmail.com>
> > To: ASP.Net Community <aspnet googlegroups.com>
> > Sent: Tuesday, March 6, 2007 9:17:06 PM
> > Subject: [asp.net:2480] ASP.NET: programmatically
adding a button adds
> > 2 buttons? help
>
> > I have a simple enough page with a form
runat=server, and am trying to
> > add ONE button programmatically, but for some
reason TWO identical
> > copies of the button are added to the page?
>
> > Sub Page_Load(ByVal sender As System.Object, ByVal
e As
> > System.EventArgs) Handles MyBase.Load
> > Dim btnSomething As New Button
> > btnSomething.Text = "added
dynamically"
> > btnSomething.ID = "button text"
> > ASPNET_form.Controls.Add(btnSomething)
> > End Sub
>
> > <form id="ASPNET_form"
runat="server">
>
> > </form>
>
> > Simple enough, or so I thought. Anyone run into
this, or am I doing
> > something wrong?
>
> >
____________________________________________________________
__________
> > ______________ Expecting? Get great news right
away with email
> > Auto-Check.
> > Try the Yahoo! Mail
> > Beta.http://advision.webevents.yahoo.com/mailbeta/newm
ail_tools.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "ASP.Net Community" group.
To post to this group, send email to aspnet googlegroups.com
To unsubscribe from this group, send email to
aspnet-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/aspnet?hl=en
-~----------~----~----~----~------~----~------~--~---
|