Solved

ASP.NET + Dynamically Generated LinkButton Not firing Command

Posted on 2016-07-24
2
44 Views
Last Modified: 2016-07-24
I am dynamically generating Linkbuttons on a page depending on how many rows pulled from a datatable.  The problem is when i click the button nothng happens.

I belive it is because when the page postbacks the buttons need to be created again, but I am not sure how to do this as the linkbuttons are generated from the datatable.

                
                LinkButton lnkbtn = new LinkButton();

                Count++;
                lnkbtn.ID = "Home_" + (Count);
                lnkbtn.Text = HomeTeamName;
                lnkbtn.CommandArgument = homesupCID;
                lnkbtn.CommandName = "ViewScores";
                lnkbtn.EnableViewState = true;
                lnkbtn.Command += new CommandEventHandler(LinkButton_Command);

    void LinkButton_Command(object sender, CommandEventArgs e)
    {

        var lb = (LinkButton)sender;

    }

Open in new window


HomeTeamName, homesupCID are populated from the databable, there is other data from the datatable used for other things inside the function.

How do i get this to work ?
0
Comment
Question by:dkilby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 500 total points
ID: 41726903
You have to make sure the DataTable is re-created on postback. You can hide the DataTable until if/when it is needed.
0
 

Author Closing Comment

by:dkilby
ID: 41726912
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question