Dynamically Created Controls

Discussion in 'ASP .Net' started by accyboy1981, Aug 31, 2006.

  1. accyboy1981

    accyboy1981 Guest

    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
    accyboy1981, Aug 31, 2006
    #1
    1. Advertising

  2. accyboy1981

    Mark Rae Guest

    "accyboy1981" <> wrote in message
    news:...

    > 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...
    Mark Rae, Aug 31, 2006
    #2
    1. Advertising

  3. accyboy1981

    imransyed63

    Joined:
    May 16, 2006
    Messages:
    27
    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"
    imransyed63, Aug 31, 2006
    #3
  4. accyboy1981

    accyboy1981 Guest

    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
    accyboy1981, Sep 1, 2006
    #4
  5. accyboy1981

    Mark Rae Guest

    Mark Rae, Sep 1, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Donaldson
    Replies:
    0
    Views:
    419
    Bryan Donaldson
    Nov 24, 2003
  2. Brian Smith
    Replies:
    4
    Views:
    704
    Brian Smith
    Jan 9, 2004
  3. Colin McGuigan
    Replies:
    2
    Views:
    743
    Colin McGuigan
    Feb 6, 2004
  4. =?Utf-8?B?Q0ogU21pdA==?=

    Finding Dynamically Created DataGrid Controls

    =?Utf-8?B?Q0ogU21pdA==?=, Feb 25, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    424
    Steven Cheng[MSFT]
    Feb 26, 2004
  5. msimmons
    Replies:
    0
    Views:
    460
    msimmons
    Jul 16, 2009
Loading...

Share This Page