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

Posted on 2014-09-02
Last Modified: 2014-09-03
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?
Question by:CipherIS
    LVL 22

    Accepted 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.
    LVL 1

    Author Comment

    I'm receiving a "New line in constant" error.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 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

    9 Experts available now in Live!

    Get 1:1 Help Now