473,729 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best design practices for user control interaction

Here is my question:

It is common to have many pieces of business logic encapsulated within
asp.net user controls. This can be found in high visibility projects
such as the iBuySpy portal from MS. Virtually every bit of the site
is encapsulated within user controls. The problem begins when you try
to have user controls pass information to one another as well as to
their parent form. This can be accomplished by creating public
properties of the user controls, and then referencing those properties
to get around the issue of the parents page load event occuring before
the event handler in the user control (assuming that you have an event
that needs to send information to the parent page). This is great as
long as you can easily create a public property that can return what
you need from the user control before its event handler fires (such as
grabbing text from a user input text box) But what about more complex
needs, such as a user control that contains a datagrid that a user can
select a record which then needs to pass information from that record
to a different user control on the same page? This can be very
convoluted -although it is possibly to get around most of these
issues, I'm just wondering if there are better ways to handle this
kind of interoperabilit y or if we are stuck with public properties for
most applications...
Nov 18 '05 #1
4 2443

Check out the concept called Event Bubbling. It allows an event thrown
inside an inner control to propagate out to the outer controls. Most
controls make use of Control.OnBubbl eEvent

-Oleg.
"Josh Harris" <jh*****@securi tytrustco.com> wrote in message
news:80******** *************** **@posting.goog le.com...
Here is my question:

It is common to have many pieces of business logic encapsulated within
asp.net user controls. This can be found in high visibility projects
such as the iBuySpy portal from MS. Virtually every bit of the site
is encapsulated within user controls. The problem begins when you try
to have user controls pass information to one another as well as to
their parent form. This can be accomplished by creating public
properties of the user controls, and then referencing those properties
to get around the issue of the parents page load event occuring before
the event handler in the user control (assuming that you have an event
that needs to send information to the parent page). This is great as
long as you can easily create a public property that can return what
you need from the user control before its event handler fires (such as
grabbing text from a user input text box) But what about more complex
needs, such as a user control that contains a datagrid that a user can
select a record which then needs to pass information from that record
to a different user control on the same page? This can be very
convoluted -although it is possibly to get around most of these
issues, I'm just wondering if there are better ways to handle this
kind of interoperabilit y or if we are stuck with public properties for
most applications...

Nov 18 '05 #2
I commonly use the PreRender event of the page and controls for complex
situations like this.
By the time the PreRender event happens, the page is loaded and all its
controls have received their events. So you are now in a very stateful
moment which makes it easier to communicate among various controls.

Of course knowledge is power. I suggest you study the lifecycle of pages
and controls.
Here are some good articles on the subject:
http://www.15seconds.com/issue/020102.htm
http://msdn.microsoft.com/library/de...singStages.asp
http://msdn.microsoft.com/library/de...nlifecycle.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Josh Harris" <jh*****@securi tytrustco.com> wrote in message
news:80******** *************** **@posting.goog le.com...
Here is my question:

It is common to have many pieces of business logic encapsulated within
asp.net user controls. This can be found in high visibility projects
such as the iBuySpy portal from MS. Virtually every bit of the site
is encapsulated within user controls. The problem begins when you try
to have user controls pass information to one another as well as to
their parent form. This can be accomplished by creating public
properties of the user controls, and then referencing those properties
to get around the issue of the parents page load event occuring before
the event handler in the user control (assuming that you have an event
that needs to send information to the parent page). This is great as
long as you can easily create a public property that can return what
you need from the user control before its event handler fires (such as
grabbing text from a user input text box) But what about more complex
needs, such as a user control that contains a datagrid that a user can
select a record which then needs to pass information from that record
to a different user control on the same page? This can be very
convoluted -although it is possibly to get around most of these
issues, I'm just wondering if there are better ways to handle this
kind of interoperabilit y or if we are stuck with public properties for
most applications...

Nov 18 '05 #3
Josh,

I'm not familiar with IBuySpy but I've seen other complaints about how it's
advertised as
'best practices'. I think a lot of the apps at asp.net are good for
different techniques but
not neccessarily for architecting a large app.

Typically one would want to keep business logic in classes separate from the
controls.

User controls can be very tricky with the situations you describe,
especially if they're loaded dynamically (is this the case here? I spent a
lot of time trying to get this straight.)

You may want to use public properties of the page rather than the properties
of the control.
You could use event bubbling as noted in another post or do this:

(The page in this case is MainReport.aspx )
Dim myParent As MainReport
myParent = CType(HttpConte xt.Current.Hand ler, MainReport)
myParent.SomeFu nction()

The page would probably have an variable declared for other controls, so you
wouldn't have to
do stuff like myParent.Parent .FindControl(.. .

Jim

"Josh Harris" <jh*****@securi tytrustco.com> wrote in message
news:80******** *************** **@posting.goog le.com...
Here is my question:

It is common to have many pieces of business logic encapsulated within
asp.net user controls. This can be found in high visibility projects
such as the iBuySpy portal from MS. Virtually every bit of the site
is encapsulated within user controls. The problem begins when you try
to have user controls pass information to one another as well as to
their parent form. This can be accomplished by creating public
properties of the user controls, and then referencing those properties
to get around the issue of the parents page load event occuring before
the event handler in the user control (assuming that you have an event
that needs to send information to the parent page). This is great as
long as you can easily create a public property that can return what
you need from the user control before its event handler fires (such as
grabbing text from a user input text box) But what about more complex
needs, such as a user control that contains a datagrid that a user can
select a record which then needs to pass information from that record
to a different user control on the same page? This can be very
convoluted -although it is possibly to get around most of these
issues, I'm just wondering if there are better ways to handle this
kind of interoperabilit y or if we are stuck with public properties for
most applications...

Nov 18 '05 #4
Ok, first thing, I have no idea why I said it is common to encapsulate
business login in a user control, I did not mean to say that in any
way, what I meant to say is that it is very usefull to be able to have
user controls talk to one another, such as one user control takes user
input, and another displays information based on what the user
entered...
Jim, Yes the controls are added dynamically.

Steve, I can't user page_prerender in the parent page when trying to
pass information from a user control to another user control. (but
thanks for the links)

I have also encountered a new *feature*, apparently when using any
type of caching on a user control, output caching, fragment caching,
etc, you can no longer find the control using the findcontrol method.
I realize that this is because when the control is cached it is
removed from the pages control collection (although I'm not convinced
that is the best architecture) but then where IS the control placed?
how can I easily access a cached control with a findcontrol sort of
method?

Thanks,
Josh
Nov 18 '05 #5

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

Similar topics

11
9266
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
136
9426
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
3
4140
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
14
3134
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them... (both are "Pascal Case" with no leading or trailing qualifiers). For example... I'll be modelling something, e.g. a computer, and I'll
4
460
by: Josh Harris | last post by:
Here is my question: It is common to have many pieces of business logic encapsulated within asp.net user controls. This can be found in high visibility projects such as the iBuySpy portal from MS. Virtually every bit of the site is encapsulated within user controls. The problem begins when you try to have user controls pass information to one another as well as to their parent form. This can be accomplished by creating public...
10
3472
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
5
2530
by: BK | last post by:
We've got a fairly large scale development process under way in .NET 2003. We are about a month away from go-live for phase 1, second phase is rather short and all work should be completed in the next 2 months. Looking back on problems encountered, we want to learn from this project. FWIW, we are nearly on time with the original time line (only off by about a month), and we actually added more functionality than the original specs...
4
1840
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is logged in, on each and every page, and redirects the user to a login page if s/he's not logged in. The login page will also take care of some standard setup, such as choosing/populating a user profile. I used to use <!-- #include ... --for this,...
0
1995
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and practices site and it just isn't sinking in all that clearly to me. Currently we have code in production and it all works well, however it is not the way we want it. We know that we can implement a better design plan to improve performance,...
0
8921
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.