Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Dynamic LinkButton not firing it's events.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mufasa - 21 Apr 2008 13:31 GMT
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 - 21 Apr 2008 15:00 GMT
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...

>I have code to dynamically generate some link buttons (It's not know how
>many are needed until runtime.)
[quoted text clipped - 30 lines]
>
> TIA - Jeff.
Mufasa - 21 Apr 2008 16:10 GMT
Thanks for the help.

I was creating the objects in pre-render.

> At which moment do you create your LinkButton
> Check http://msdn2.microsoft.com/en-us/library/ms178472.aspx "ASP.NET Page
[quoted text clipped - 36 lines]
>>
>> TIA - Jeff.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.