Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamic LinkButton not firing it's events.

Reply
Thread Tools

Dynamic LinkButton not firing it's events.

 
 
Mufasa
Guest
Posts: n/a
 
      04-21-2008
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.


 
Reply With Quote
 
 
 
 
George Ter-Saakov
Guest
Posts: n/a
 
      04-21-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>
>



 
Reply With Quote
 
 
 
 
Mufasa
Guest
Posts: n/a
 
      04-21-2008
Thanks for the help.

I was creating the objects in pre-render.

"George Ter-Saakov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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.
>>
>>

>
>



 
Reply With Quote
 
bharat.garg bharat.garg is offline
Junior Member
Join Date: Jun 2009
Posts: 1
 
      06-15-2009
but i want to add it on some button click event then what to do?
kindly reply asap.
 
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
Linkbutton does not look like a linkbutton Sathyaish ASP .Net 3 09-08-2005 09:41 AM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net Datagrid Control 1 09-08-2005 08:44 AM
LinkButton event not firing Mantorok ASP .Net 1 02-21-2005 01:44 PM
Event not firing from dynamically added linkbutton JoakimR ASP .Net 3 01-08-2005 05:56 PM
DataGrid LinkButton Not Firing Glenn Owens ASP .Net 0 06-25-2004 02:27 PM



Advertisments