ID of sender ?

G

Guest

Really simple I think..! I have a function to be used by two textboxes on the
textchanged event, but i need to know which textbox i came from.

public void set_SomethingElse(Object sender, EventArgs e) {
sender.ID returns error: object does not contain definition for ID.

I'm using C#

what am I missing?
 
J

John M Deal

You need to cast the sender object to the appropriate type (in this case
text box) then check its Id. For example:

string id = string.Empty;
TextBox senderBox = sender as TextBox;
if (senderBox != null)
{
id = senderBox.ID;
}
//You id should be here or if the item wasn't a text box it would still
be string.Empty

Have A Better One!

John M Deal, MCP
Necessity Software
 
G

Guest

Great. Would have thought it could work out what type of control it had come
from though. Thanks!
 
G

Guest

Hi,
I tried, it's not the control which fires the postback event. It's page name.
Why?

william
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top