Cast sender object in event handler using GetType().Name

You never have to cast. I used to think the same way when I started, this ‘pattern’ is incorrect, and not really logical.

Your best bet is to use something like:

if (sender is TextBox)
{
  TextBox tb = (TextBox)sender;
}
else if (sender is RichTextBox)
{
  RichTextBox rtb = (RichTextBox)sender;
}
else
{
  // etc
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)