Dynamically Created Controls

A

accyboy1981

Hi,

I have created a method that creates a link button dynamically and
places it within a place holder. The code I have creates the button,
but when it is clicked the button method is not fired. Below is the
code the creates the button:

LinkButton lb1 = new LinkButton();
lb1.ID = "lb1" + day.ToString( "ddMMMyyyy" );
lb1.Text = day.ToString( "dd" );
lb1.SkinID = "linkButtonSkin3";
lb1.CommandArgument = day.ToString( "ddMMMyyyy" );
lb1.Click += new EventHandler( EditDay );

A unique ID is given for every button.

I am unsing Visual Studio 2005 and Asp.net 2.0.

Any help on this would be much appreciated.

Thanks in advance.

Simon
 
M

Mark Rae

I have created a method that creates a link button dynamically and
places it within a place holder. The code I have creates the button,
but when it is clicked the button method is not fired. Below is the
code the creates the button:

LinkButton lb1 = new LinkButton();
lb1.ID = "lb1" + day.ToString( "ddMMMyyyy" );
lb1.Text = day.ToString( "dd" );
lb1.SkinID = "linkButtonSkin3";
lb1.CommandArgument = day.ToString( "ddMMMyyyy" );
lb1.Click += new EventHandler( EditDay );

A unique ID is given for every button.

I am unsing Visual Studio 2005 and Asp.net 2.0.

Any help on this would be much appreciated.

In which Page method are you creating the control? I'm betting you're not
creating it in Page_Init...
 
Joined
May 16, 2006
Messages
27
Reaction score
0
Complete code

can u paste the complete code, how r u placing the label into place holder and how did u defined the event of the label "EditDay"
 
A

accyboy1981

Hi,

Thanks for the response.

I've tried creating the buttons in the Page_Init, but the problem with
this is that I dont know the name as it will be dynamically choosen.

Basically what I am doing is creating a calendar for a year, and when a
user clicks a specific date if post-backs and runs a different method.
When it doen this the calendar is not drawn so this button will not
appear on the page. I am trying to pass the date that was clicked in
the commandargument so all I need is one method for the 365 days a user
can click. The problem I am finding is that because the button is not
drawn once it has been clicked it cannot be found.

Is there any way around this? Is it possible to have dynamic controls
this way on the same page?

Any help would be appreciated

Thanks

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top