Solved

ASP.NET + Dynamically Generated LinkButton Not firing Command

Posted on 2016-07-24
2
26 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
2 Comments
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now