ID of sender ?

Discussion in 'ASP .Net' started by =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 19, 2004.

  1. 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?
     
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 19, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    John M Deal Guest

    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

    louise raisbeck wrote:
    > 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?
     
    John M Deal, Nov 19, 2004
    #2
    1. Advertising

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

    "John M Deal" wrote:

    > 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
    >
    > louise raisbeck wrote:
    > > 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?

    >
     
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 19, 2004
    #3
  4. Hi,
    I tried, it's not the control which fires the postback event. It's page name.
    Why?

    william

    "louise raisbeck" wrote:

    > Great. Would have thought it could work out what type of control it had come
    > from though. Thanks!
    >
    > "John M Deal" wrote:
    >
    > > 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
    > >
    > > louise raisbeck wrote:
    > > > 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?

    > >
     
    =?Utf-8?B?d2lsbGlhbQ==?=, Jan 26, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    2
    Views:
    1,817
    Showjumper
    Aug 2, 2003
  2. Dylan Parry
    Replies:
    2
    Views:
    561
  3. Replies:
    0
    Views:
    403
  4. Replies:
    0
    Views:
    364
  5. jodleren
    Replies:
    2
    Views:
    111
    Thomas 'PointedEars' Lahn
    Jan 31, 2008
Loading...

Share This Page