473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

User Controls and Postback

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
Nov 17 '05 #1
3 2989
"Cathie" <so*****@miscrosoft.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
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.
--
John
Nov 17 '05 #2
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

"John Saunders" <john.saunders at surfcontrol.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
"Cathie" <so*****@miscrosoft.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
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.
--
John

Nov 17 '05 #3
"Cathie" <so*****@miscrosoft.com> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
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"].
--
John
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Ramey | last post by:
Howdy, I think I have a good question! I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which...
3
by: buran | last post by:
Dear ASP.NET Programmers, I am loading a web user control ("taclient.ascx") into a placeholder (ID: phFA). The web user control contains a cancel button (ID: btnCancel). I would like to "unload"...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
6
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
8
by: Mats Lycken | last post by:
Hi, I'm working on a webproject where I have several different user controls loaded on a WebForm. A problem arises when I in one webcontrol makes a change that should be picked up by another user...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.