472,790 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 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 2387

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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.