Dynamic LinkButton not firing it's events.

Discussion in 'ASP .Net' started by Mufasa, Apr 21, 2008.

  1. Mufasa

    Mufasa Guest

    I have code to dynamically generate some link buttons (It's not know how
    many are needed until runtime.)

    I am adding the linkbutton to a cell in a table and the adding works fine.
    It's firing of the event doesn't seem to be happening. Am I missing
    something?

    Here's the code:

    To create the link button:

    ldrCell = new TableCell();
    LinkButton lbLink = new LinkButton();
    lbLink.Text = "Button - " + ldrCatRow["ProductDesc"].ToString();
    lbLink.CommandName = "Desc";
    lbLink.CommandArgument = "FieldValue";
    lbLink.Command += new CommandEventHandler(LinkButton1_Command);
    lbLink.Click += new EventHandler(LinkButton1_Click);

    ldrCell.Controls.Add(lbLink);


    And the code that handles the events:
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
    string lstemp = e.CommandArgument.ToString();
    string lsmsg = lstemp + " ----";
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
    string lstemp = "It was clicked.";
    string lsmsg = lstemp + " --------";
    }


    TIA - Jeff.
    Mufasa, Apr 21, 2008
    #1
    1. Advertising

  2. At which moment do you create your LinkButton
    Check http://msdn2.microsoft.com/en-us/library/ms178472.aspx "ASP.NET Page
    Life Cycle "

    You should be done with it before Load event...



    "Mufasa" <> wrote in message
    news:...
    >I have code to dynamically generate some link buttons (It's not know how
    >many are needed until runtime.)
    >
    > I am adding the linkbutton to a cell in a table and the adding works fine.
    > It's firing of the event doesn't seem to be happening. Am I missing
    > something?
    >
    > Here's the code:
    >
    > To create the link button:
    >
    > ldrCell = new TableCell();
    > LinkButton lbLink = new LinkButton();
    > lbLink.Text = "Button - " + ldrCatRow["ProductDesc"].ToString();
    > lbLink.CommandName = "Desc";
    > lbLink.CommandArgument = "FieldValue";
    > lbLink.Command += new CommandEventHandler(LinkButton1_Command);
    > lbLink.Click += new EventHandler(LinkButton1_Click);
    >
    > ldrCell.Controls.Add(lbLink);
    >
    >
    > And the code that handles the events:
    > protected void LinkButton1_Command(object sender, CommandEventArgs e)
    > {
    > string lstemp = e.CommandArgument.ToString();
    > string lsmsg = lstemp + " ----";
    > }
    > protected void LinkButton1_Click(object sender, EventArgs e)
    > {
    > string lstemp = "It was clicked.";
    > string lsmsg = lstemp + " --------";
    > }
    >
    >
    > TIA - Jeff.
    >
    >
    George Ter-Saakov, Apr 21, 2008
    #2
    1. Advertising

  3. Mufasa

    Mufasa Guest

    Thanks for the help.

    I was creating the objects in pre-render.

    "George Ter-Saakov" <> wrote in message
    news:...
    > At which moment do you create your LinkButton
    > Check http://msdn2.microsoft.com/en-us/library/ms178472.aspx "ASP.NET Page
    > Life Cycle "
    >
    > You should be done with it before Load event...
    >
    >
    >
    > "Mufasa" <> wrote in message
    > news:...
    >>I have code to dynamically generate some link buttons (It's not know how
    >>many are needed until runtime.)
    >>
    >> I am adding the linkbutton to a cell in a table and the adding works
    >> fine. It's firing of the event doesn't seem to be happening. Am I missing
    >> something?
    >>
    >> Here's the code:
    >>
    >> To create the link button:
    >>
    >> ldrCell = new TableCell();
    >> LinkButton lbLink = new LinkButton();
    >> lbLink.Text = "Button - " + ldrCatRow["ProductDesc"].ToString();
    >> lbLink.CommandName = "Desc";
    >> lbLink.CommandArgument = "FieldValue";
    >> lbLink.Command += new CommandEventHandler(LinkButton1_Command);
    >> lbLink.Click += new EventHandler(LinkButton1_Click);
    >>
    >> ldrCell.Controls.Add(lbLink);
    >>
    >>
    >> And the code that handles the events:
    >> protected void LinkButton1_Command(object sender, CommandEventArgs e)
    >> {
    >> string lstemp = e.CommandArgument.ToString();
    >> string lsmsg = lstemp + " ----";
    >> }
    >> protected void LinkButton1_Click(object sender, EventArgs e)
    >> {
    >> string lstemp = "It was clicked.";
    >> string lsmsg = lstemp + " --------";
    >> }
    >>
    >>
    >> TIA - Jeff.
    >>
    >>

    >
    >
    Mufasa, Apr 21, 2008
    #3
  4. Mufasa

    bharat.garg

    Joined:
    Jun 15, 2009
    Messages:
    1
    add link button dynamically

    but i want to add it on some button click event then what to do?
    kindly reply asap.
    bharat.garg, Jun 15, 2009
    #4
    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. =?Utf-8?B?U2hvdXJpZQ==?=
    Replies:
    1
    Views:
    7,875
    =?Utf-8?B?U2hvdXJpZQ==?=
    Jan 21, 2004
  2. Glenn Owens

    DataGrid LinkButton Not Firing

    Glenn Owens, Jun 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    523
    Glenn Owens
    Jun 25, 2004
  3. Sathyaish
    Replies:
    3
    Views:
    3,087
    Sathyaish
    Sep 8, 2005
  4. SevDer
    Replies:
    2
    Views:
    1,287
    Walter Wang [MSFT]
    Nov 13, 2007
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    176
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page