Home All Groups Group Topic Archive Search About
Author
28 Nov 2007 5:44 PM
Mr. Arnold
I am building dynamic textboxes in C#. The TextChanged Event for  the
textboxs are tied to one Event Handler.

When the event is fired is there a way of finding out by textbox.Name or
something  else as to which textbox is firing the event?

Author
28 Nov 2007 7:23 PM
Jeff Gaines
On 28/11/2007 in message <#ZqMIZeMIHA.5***@TK2MSFTNGP04.phx.gbl> Mr.
Arnold wrote:

>I am building dynamic textboxes in C#. The TextChanged Event for  the
>textboxs are tied to one Event Handler.
>
>When the event is fired is there a way of finding out by textbox.Name or
>something  else as to which textbox is firing the event?

You can do this:

private void txtTime_TextChanged(object sender, EventArgs e)
{
    TextBox txtTemp = sender as TextBox;
}

Then txtTemp will be the TextBox that fired the event.

--
Jeff Gaines
Author
28 Nov 2007 11:12 PM
Mr. Arnold
Show quote
"Jeff Gaines" <whitedragon@newsgroups.nospam> wrote in message
news:xn0fe8p2c7m747j004@msnews.microsoft.com...
> On 28/11/2007 in message <#ZqMIZeMIHA.5***@TK2MSFTNGP04.phx.gbl> Mr.
> Arnold wrote:
>
>>I am building dynamic textboxes in C#. The TextChanged Event for  the
>>textboxs are tied to one Event Handler.
>>
>>When the event is fired is there a way of finding out by textbox.Name or
>>something  else as to which textbox is firing the event?
>
> You can do this:
>
> private void txtTime_TextChanged(object sender, EventArgs e)
> {
> TextBox txtTemp = sender as TextBox;
> }
>
> Then txtTemp will be the TextBox that fired the event.
>

Thanks

After hitting Google for about 20 minutes or so at work, I came upon this
method.

TextBox tb = (TextBox)sender;

It's just another way of doing it I guess.

AddThis Social Bookmark Button