Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which Control caused PostBack?

Status
Not open for further replies.

Muddmuse

Programmer
Jul 31, 2001
85
0
0
US
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()?
 
How about setting a session variable in both the drop down list and on the button click?

e.g.

On the drop down list set session("whopostedback") = "MyDropDownList" and on the button click set session("whopostedback") = "MyButton".

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
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?
 
You can use the sender object I think to determine which control it was.

Quick google search came up with which at a quick glance looks to be what you need.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top