Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamically Created Controls

Reply
Thread Tools

Dynamically Created Controls

 
 
accyboy1981
Guest
Posts: n/a
 
      08-31-2006
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

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      08-31-2006
"accyboy1981" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

> 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...


 
Reply With Quote
 
 
 
 
imransyed63 imransyed63 is offline
Member
Join Date: May 2006
Posts: 31
 
      08-31-2006
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"
 
Reply With Quote
 
accyboy1981
Guest
Posts: n/a
 
      09-01-2006
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

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      09-01-2006
"accyboy1981" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...

> 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.


That's what ClientID is for...
http://www.codeproject.com/aspnet/re...in_asp_net.asp


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
Getting values from dynamically created controls in a DataGrid Colin McGuigan ASP .Net 2 02-06-2004 12:03 PM
Accessing values for Dynamically created controls Brian Smith ASP .Net 4 01-09-2004 09:00 PM
retrieving values from controls dynamically created in a <asp:table> Bryan Donaldson ASP .Net 0 11-24-2003 06:29 PM



Advertisments