473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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["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.
Jun 27 '08 #1
2 1898
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.comwrote in message
news:Oy**************@TK2MSFTNGP02.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["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.


Jun 27 '08 #2
Thanks for the help.

I was creating the objects in pre-render.

"George Ter-Saakov" <gt****@cardone.comwrote in message
news:ex**************@TK2MSFTNGP05.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.comwrote in message
news:Oy**************@TK2MSFTNGP02.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["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.



Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill | last post by:
I'm trying to dynamically build several linkbuttons and wire them up to a method called OnLinkClick . . . For the life of me, I don't understand why the code below isn't firing the event. ...
1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
3
by: JoakimR | last post by:
Hello, I have a problem with events not firing. I've created a web user control which renders a calendar using a table control. In two cells I'm adding LinkButtons for "prev/next month". However,...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
4
by: Fueled | last post by:
Hi everyone! I've made quite a lot of research on this, and I've tried a couple of proposed solutions. Nothing has worked for me, but I feel there's not much I'm missing. So I'm turning to this...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.