I have a dropdown list and button that cause postback, each with events that are getting fired correctly after Page_Load. How can I determine which control caused the postback in OnInit()?
The site is session-less so that's not an option. Any other ideas? OnInit() takes System.EventArgs as an argument but it appears to be empty all the time. Are there any properties of this object that would tell me the control that caused postback?
The easiest way to do this is to have a common code block that the event handler of the respective controls calls. In other words, you don't need to access anything in the Page_Load/OnInit(), rather you can simply do something like:
Code:
//in DropDownList event handler
DoStuff( sender );
//in Button event handler
DoStuff( sender );
//in your function
private void DoStuff( Control c )
{
if( c is DropDownList )
//blah blah blah
else if( c is Button )
//blah blah blah
}
You can also check the id in DoStuff if you need to.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.