Dynamic LinkButton not firing it's events.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mufasa

    Dynamic LinkButton not firing it's events.

    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["ProductDes c"].ToString();
    lbLink.CommandN ame = "Desc";
    lbLink.CommandA rgument = "FieldValue ";
    lbLink.Command += new CommandEventHan dler(LinkButton 1_Command);
    lbLink.Click += new EventHandler(Li nkButton1_Click );

    ldrCell.Control s.Add(lbLink);


    And the code that handles the events:
    protected void LinkButton1_Com mand(object sender, CommandEventArg s e)
    {
    string lstemp = e.CommandArgume nt.ToString();
    string lsmsg = lstemp + " ----";
    }
    protected void LinkButton1_Cli ck(object sender, EventArgs e)
    {
    string lstemp = "It was clicked.";
    string lsmsg = lstemp + " --------";
    }


    TIA - Jeff.


  • George Ter-Saakov

    #2
    Re: Dynamic LinkButton not firing it's events.

    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" <jb@nowhere.com wrote in message
    news:OyzEou6oIH A.5016@TK2MSFTN GP02.phx.gbl...
    >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["ProductDes c"].ToString();
    lbLink.CommandN ame = "Desc";
    lbLink.CommandA rgument = "FieldValue ";
    lbLink.Command += new CommandEventHan dler(LinkButton 1_Command);
    lbLink.Click += new EventHandler(Li nkButton1_Click );
    >
    ldrCell.Control s.Add(lbLink);
    >
    >
    And the code that handles the events:
    protected void LinkButton1_Com mand(object sender, CommandEventArg s e)
    {
    string lstemp = e.CommandArgume nt.ToString();
    string lsmsg = lstemp + " ----";
    }
    protected void LinkButton1_Cli ck(object sender, EventArgs e)
    {
    string lstemp = "It was clicked.";
    string lsmsg = lstemp + " --------";
    }
    >
    >
    TIA - Jeff.
    >
    >

    Comment

    • Mufasa

      #3
      Re: Dynamic LinkButton not firing it's events.

      Thanks for the help.

      I was creating the objects in pre-render.

      "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
      news:ex7AGg7oIH A.4672@TK2MSFTN GP05.phx.gbl...
      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" <jb@nowhere.com wrote in message
      news:OyzEou6oIH A.5016@TK2MSFTN GP02.phx.gbl...
      >>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["ProductDes c"].ToString();
      > lbLink.CommandN ame = "Desc";
      > lbLink.CommandA rgument = "FieldValue ";
      > lbLink.Command += new CommandEventHan dler(LinkButton 1_Command);
      > lbLink.Click += new EventHandler(Li nkButton1_Click );
      >>
      > ldrCell.Control s.Add(lbLink);
      >>
      >>
      >And the code that handles the events:
      >protected void LinkButton1_Com mand(object sender, CommandEventArg s e)
      >{
      > string lstemp = e.CommandArgume nt.ToString();
      > string lsmsg = lstemp + " ----";
      >}
      >protected void LinkButton1_Cli ck(object sender, EventArgs e)
      >{
      > string lstemp = "It was clicked.";
      > string lsmsg = lstemp + " --------";
      >}
      >>
      >>
      >TIA - Jeff.
      >>
      >>
      >
      >

      Comment

      Working...