[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

ASP.NET - C# LinkButton Sender.Attributes Not Working

I am generating a list of people.  I am using the link button to allow a user to click on a person to get info on that person and continue processing on another page.

I have the below code on my .NET page
 <asp:LinkButton ID="lbPerson" runat="server" OnClick="selectPerson" 
                                EmpID='<%# DataBinder.Eval(Container, "DataItem.emp_id")%>' 
                                FirstName='<%#DataBinder.Eval(Container, "dataItem.ins_first") %>' 
                                LastName='<%#DataBinder.Eval(Container, "dataItem.ins_last") %>' >
                                <%#DataBinder.Eval(Container, "dataItem.ins_first") %>&nbsp<%#DataBinder.Eval(Container, "dataItem.ins_last") %>

Open in new window

I have the below code in my code behind page

    protected void selectPerson(object sender, EventArgs e)

        LinkButton _sender = (LinkButton)sender;
        string firstName = _sender.Attributes["FirstName"].ToString();
        string lastName = _sender.Attributes["LastName"].ToString();
        int empID = Convert.ToInt32(_sender.Attributes["EmpID"].ToString());

Open in new window

As I walk through the code all of the attributes are "NULL".  i have used this same code in numerous applications and I do not see why it's not working here.  Any ideas?
1 Solution
you can do it in different way like passing parameters to same function like:

<asp:LinkButton ID="lbPerson" runat="server" 
  OnClick="selectPerson('<%# Eval("DataItem.emp_id")%>', '<%#Eval("dataItem.ins_first") %>', '<%#Eval("dataItem.ins_last") %>')" >
<%#Eval("dataItem.ins_first") %>&nbsp<%#Eval("dataItem.ins_last") %>

Open in new window

and in code behind function is:

protected void selectPerson(object empid, object fname, object lname)


Open in new window

Hope this helps you.
CipherISAuthor Commented:
I'm receiving a "New line in constant" error.

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now