User Controls and Postback

  • Thread starter Thread starter Cathie
  • Start date Start date
C

Cathie

Hi All,

I have a few user controls on a page and I need to determine which control
caused the PostBack. Is there anyway to do this?

Thanks in advance,
Cathie
 
Cathie said:
Hi All,

I have a few user controls on a page and I need to determine which control
caused the PostBack. Is there anyway to do this?

First of all, user controls don't usually cause post backs. Usually it's
controls in the user control which cause postbacks.

Second, you may want to review your reasons for wanting to know which
control caused the postback. In most cases this sort of thing is better done
simply by handling the control's postback event (Click for Buttons,
SelectedIndexChanged for a DropDownList, etc).

The one exception to this (I've been taught here) is when you are using a
control mostly for its value. For instance, if you have an AutoPostBack
DropDownList and need to use the new value to set parameters for a query in
Page_Load.
 
Yes I generally handle the postback of the control within the user control
in the user controls code behind. No problem. But yes I have a situation
where I need the value in the outer-page which impacts the query that is
being sent to the user control.

So how can you tell which user control (that is control within the user
control) caused the postback?

thanks for your input,
Cathie
 
Cathie said:
Yes I generally handle the postback of the control within the user control
in the user controls code behind. No problem. But yes I have a situation
where I need the value in the outer-page which impacts the query that is
being sent to the user control.

So how can you tell which user control (that is control within the user
control) caused the postback?

I'd encapsulate this feature in the user control itself. The page shouldn't
have to know details of controls inside of the user control. Also, if you
only want the value, you don't want the page to have access to the posting
control, only to the value of the posting control, right?

If this is the case, I'd create a public property in the user control which
would look at the Request.Form collection. In particular, controls which
post back using the __doPostBack JavaScript function will show their
UniqueID in Request.Form["__EVENTTARGET"].
 
Back
Top