Avatar of dkilby
dkilby
Flag for Canada asked on

ASP.NET + Dynamically Generated LinkButton Not firing Command

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 ?
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
dkilby

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
funwithdotnet

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dkilby

ASKER
Thanks
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes