?
Solved

ASP.NET + Dynamically Generated LinkButton Not firing Command

Posted on 2016-07-24
2
Medium Priority
?
45 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 2000 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 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