Solved

ASP.NET + Dynamically Generated LinkButton Not firing Command

Posted on 2016-07-24
2
38 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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