473,394 Members | 1,761 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,394 software developers and data experts.

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 interoperability or if we are stuck with public properties for
most applications...
Nov 18 '05 #1
4 2428

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.OnBubbleEvent

-Oleg.
"Josh Harris" <jh*****@securitytrustco.com> wrote in message
news:80*************************@posting.google.co m...
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 interoperability 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*****@securitytrustco.com> wrote in message
news:80*************************@posting.google.co m...
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 interoperability 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(HttpContext.Current.Handler, MainReport)
myParent.SomeFunction()

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*****@securitytrustco.com> wrote in message
news:80*************************@posting.google.co m...
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 interoperability 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
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...
136
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...
3
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....
14
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......
4
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...
10
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...
5
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...
4
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.