How do I get the object id from sender when the object s in a materpage in .net 2010?

I have a page that uses a master page. In the content placeholder I have a update panel. In this update panel I am dynamically creating buttons. I need to be able to get the id from the sender object in the generic button event I have created.

I have tried to get the type of object by:
Type t = sender.GetType(), but The object comes back blank. I

 I have a feeling that it's because I have the object in a bunch of parent controls. How would I get the id back from the sender in this scenario?

Thanks in advance!

Both have gotten me nowhere. Is there someth id back from the sender?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill NolanOwner, Lead Technology ProgrammerCommented:
Where does 'sender' come from?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bschave2Author Commented:
the object that sends it, but am getting nothing back.
bschave2Author Commented:
also tried  Button btn = ((Button)sender);
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Daniel Van Der WerkenIndependent ConsultantCommented:
try this.

Type t = typeof( sender );

make sure sender isn't null too.
bschave2Author Commented:
telling me that the type or namespace could not be found.

this is my .cs code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CallOptionsAvailability
    public partial class dynamic_update_panel : System.Web.UI.Page
        protected override void OnPreInit(EventArgs e)
        protected void Page_Load(object sender, EventArgs e)
            for (int i = 0; i < 3; i++)
                Table tbl = new Table();

                tbl.ID = "tbl" + i.ToString();
                tbl.Width = Unit.Pixel(800);

                for (int j = 0; j < 10; j++)
                    TableRow tr = new TableRow();

                    for (int k = 0; k < 5; k++)
                        TableCell tc = new TableCell();
                        tc.Text = "tbl_" + i.ToString() + "_row_" + j.ToString() + "_col_" + k.ToString();


                Literal newLn = new Literal();
                newLn.Text = "<br />";

                Button button = new Button();
                button.Text = "Update Tbl";
                button.ID = "btn_tbl_" + i.ToString(); 
                button.Click += new EventHandler(HandleButtonClick);


        private void HandleButtonClick(object sender, EventArgs eventArgs)
            Button btn = sender as Button;
            Type t = typeof(sender);
            string str = btn.ID.ToString();
            //Button btn = UpdatePanel1.TemplateControl.FindControl(str);

            string str1 = ((Control)sender).ClientID;

Open in new window

Bill NolanOwner, Lead Technology ProgrammerCommented:
a) is 'sender' null?
b) does 'Button btn = sender as Button;' work?
c) can you look over the object 'sender' in your debugger and see what it is?
bschave2Author Commented:
a) yes
b) it returns "{Text = Update Table}"
c) yes, I can see everything. I can even click on base{System.Web.UI.WebControls.WebControl} and then click on the base{System.Web.UI.Control} and I can see the id that I need. But when I try, I get null returned.
Bill NolanOwner, Lead Technology ProgrammerCommented:
If 'sender' is null, how can you read its properties in the debugger?
bschave2Author Commented:
don't know!
Bill NolanOwner, Lead Technology ProgrammerCommented:
Check the type via:

Type t = sender.GetType();
bschave2Author Commented:
I did that and it comes back null. I forgot to mention that I am also saving these objects in the viewstate, so they should not be null when the event is fired.
Bill NolanOwner, Lead Technology ProgrammerCommented:
The debugger shows it is valid...?  Check these to see if you can get somewhere::

1. Make sure you are compiling in debug mode
2. Clean & rebuild entire solution
3. Temporarily remove the UpdatePanel
bschave2Author Commented:
Attached is what I told you. I can view the id, but I cannot make make it equal to the string. result
bschave2Author Commented:
I closed and reopened .net and this works to get the id from the sent object.

string str = ((Button)sender).ID.ToString();

Thanks guys.
Bill NolanOwner, Lead Technology ProgrammerCommented:
How did you close and reopen .NET?

Yes, that would get the string.  It appears from all you've stated, and from your screenshot, that you've always had access to the button.
bschave2Author Commented:
I closed the program and then re-launched it. I didn't have access to the button. I was on a VM and sometimes get weird lack of functionality in my programs. Don't know if it's the VM connection, my home internet connection or what. The screenshot showed that I was getting the value when hovering over the .ID value on the right side of the variable.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.