ID of sender ?

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
Great. Would have thought it could work out what type of control it had come
from though. Thanks!
 
Hi,
I tried, it's not the control which fires the postback event. It's page name.
Why?

william
 
Back
Top