By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 1,922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

find details on event sender

P: n/a
When I raise an event in my ASP.NET (such as OnServerValidate), how do I
get details on the Sender in the called procedure e.g.

public void Check_Log_Details(object sender,
System.Web.UI.WebControls.ServerValidateEventArgs value)
{

}

Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Cast the parameter Sender to an appropiate class and get the information
that way.

This is a simple example using a a bit of reflection to get the type
information in string format. You could us the AS operator and if / els if
as well, maybe that is a better solution.

ex 1)

public void Check_Log_Details(object sender,

System.Web.UI.WebControls.ServerValidateEventArgs value)
{
switch(sender.GetType().ToString())
{
case "System.Web.UI.WebControls.Button":
Button btnSender = (Button)sender;
// Do whatever
break;
case "System.Web.UI.WebControls.TextBox":
TextBox txtSender = (TextBox)sender;
// Do whaterver
break;
default:
// No match
}

}

ex 2)

public void Check_Log_Details(object sender,

System.Web.UI.WebControls.ServerValidateEventArgs value)
{
if((sender as Button)!=null)
{
// It's a button,
Button btnSender = (Button)sender;
}
else if ((sender as TextBox)!=null)
{
// It's a textbox
TextBox txtSender = (TextBox)sender;
}
}

I haven't runned this code, might be that you wont get the control which
triggerd the validation in this specific scenario.

--
Patrik L÷wendahl
cshrp.net - ' Elegant code by witty programmers '
cornerstone.se - ' IT Training for professionals '
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
When I raise an event in my ASP.NET (such as OnServerValidate), how do I
get details on the Sender in the called procedure e.g.

public void Check_Log_Details(object sender,
System.Web.UI.WebControls.ServerValidateEventArgs value)
{

}

Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.