473,758 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Controls: Did I go Nuts?

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 to programming, but I am new to ASP.NET and Web application
design in general... loved the concept of user controls and dynamically
adding them to a page. So what I wound up with was an application that
dynamically loads two user controls directly onto an aspx page (inserted
into PlaceHolder controls); and one of those user controls then dynamically
loads a third user control which itself declaratively implements three
additional user controls (net result is three user controls dynamically
loaded at runtime; with one of them nested within the other; the nested one
declaratively implements three additional user controls: for a total of six
user controls: three loaded dynamically and three loaded declaratively).
*Each* user control and the aspx page use C# code-behind modules and each
hits a database to determine or retrieve (1) which user controls to load,
(2) data to show up on each, and (3) property settings for various Web
Server controls that appear on the user controls. Mind you, these user
controls are not simply small snippets. While some do not take up much
screen real-estate, each implements a certain amount of non-trivial
code-behind logic. Everything loads just fine with and with remarkable
performance considering all that's going on behind the scenes. But I think
the party has come to an end now that I'm trying to deal with saving data
back to the database. I had this grand vision of having a button on the aspx
page (not in one of the user controls) that would trigger a postback. That
works, but grabbing property values from the server controls that appear
*within the dynamically loaded* user controls is not exactly
straight-forward. I've seen plenty of tutorials on referencing a user
control from the hosting aspx page's code-behind, but things are quite
different when the user controls are (1) nested and (2) dynamically loaded
onto the page. A thread last week mentioned that dynamically loaded user
controls must be added on each successive request (Postbacks included). I
took this to mean that there is no control to which to even get a reference
during the postback - and therefore no way to read property values from Web
Server controls that exist within the dynamically loaded user controls. I
tried a few things, but eventually gave up on that approach and figured that
the Forms collection would bail me out - but it won't because it doesn't
expose all the important property values of the Web Server controls that
appear within the dynamically loaded user controls.

So, at this point I'm perfectly willing to dump this whole thing and start
over with a different design - one that omits dynamically loading user
controls that host server controls to which I'll need complete access on
Postback. Anyway, as I head off to do this redesign, I'm just wondering to
what extent I went overboard. It would certainly help me up the learning
curve (from an architectural perspective) to hear some feedback from some of
you who have implemented non trivial dynamic Web Applications.

Thanks.
Nov 18 '05 #1
1 2134

"Robert Howells" <A@B.com> wrote in message news:em******** ******@tk2msftn gp13.phx.gbl...
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 to programming, but I am new to ASP.NET and Web application
design in general... loved the concept of user controls and dynamically
adding them to a page. So what I wound up with was an application that
dynamically loads two user controls directly onto an aspx page (inserted
into PlaceHolder controls); and one of those user controls then dynamically
loads a third user control which itself declaratively implements three
additional user controls (net result is three user controls dynamically
loaded at runtime; with one of them nested within the other; the nested one
declaratively implements three additional user controls: for a total of six
user controls: three loaded dynamically and three loaded declaratively).
*Each* user control and the aspx page use C# code-behind modules and each
hits a database to determine or retrieve (1) which user controls to load,
(2) data to show up on each, and (3) property settings for various Web
Server controls that appear on the user controls. Mind you, these user
controls are not simply small snippets. While some do not take up much
screen real-estate, each implements a certain amount of non-trivial
code-behind logic. Everything loads just fine with and with remarkable
performance considering all that's going on behind the scenes. But I think
the party has come to an end now that I'm trying to deal with saving data
back to the database. I had this grand vision of having a button on the aspx
page (not in one of the user controls) that would trigger a postback. That
works, but grabbing property values from the server controls that appear
*within the dynamically loaded* user controls is not exactly
straight-forward. I've seen plenty of tutorials on referencing a user
control from the hosting aspx page's code-behind, but things are quite
different when the user controls are (1) nested and (2) dynamically loaded
onto the page. A thread last week mentioned that dynamically loaded user
controls must be added on each successive request (Postbacks included). I
took this to mean that there is no control to which to even get a reference
during the postback - and therefore no way to read property values from Web
Server controls that exist within the dynamically loaded user controls. I
tried a few things, but eventually gave up on that approach and figured that
the Forms collection would bail me out - but it won't because it doesn't
expose all the important property values of the Web Server controls that
appear within the dynamically loaded user controls.

So, at this point I'm perfectly willing to dump this whole thing and start
over with a different design - one that omits dynamically loading user
controls that host server controls to which I'll need complete access on
Postback. Anyway, as I head off to do this redesign, I'm just wondering to
what extent I went overboard. It would certainly help me up the learning
curve (from an architectural perspective) to hear some feedback from some of
you who have implemented non trivial dynamic Web Applications.

Thanks.


I think you are on the right track. Dynamically loading controls does make life
simpler in some ways.

Some remarks:
* creating the controls on postback: if you want your control to receive postback
events (button click etc), then it should exist at that point. So on the first request
you generate a page with your control, then the user clicks a button that is linked
to a server-side handler. This triggers a second request where you have to make
sure your control is again added to the page (in Page_Load or before) before
it can receive the "click message" to fire the event.
* single "save all" button: I think the best way is to derive all your controls (that you
want to respond to that "save event") from a special baseclass. This baseclass
at least has an abstract "save" method (might also be implemented and virtual).
When the "save all" button is clicked (in the page the click eventhandler is called)
then you recursively loop through all controls in the page, searching for controls
that implement your baseclass. Then you can cast to that baseclass and call
the save method.

Hans Kesting
Nov 18 '05 #2

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

Similar topics

1
320
by: Seth Guard | last post by:
(Sorry for the cross-post, but no one responded to my other thread.) When developing a web page in VS.Net, I see everything in WYSIWYG format. And when I am creating a User Control, I see that drawn the same way. However, when I drag the User Control onto my main page, I see a gray box where the User Control should be. (I was expecting to see my User Control actually *rendered* on the Design screen, similar to how FrontPage renders...
0
1540
by: Deano | last post by:
If I create 2 or more records in my subform and I then delete the main record, then all the controls on my subform disappear. Yet if there is only one record in the subform then it gets deleted ok and the controls are still there ready to await further input. Further info; Cascading Deletes are on. The subform Cycle property is set to Current Record.
0
876
by: Chris Szabo | last post by:
Hey everyone... this is nuts... really hope someone can help out. I've got eight HtmlSelect controls on the web form. They each are set to runat server. When the page is loaded, they are filled using data from a database and a loop that creates the listitems and adds them, no databinding. If there is a query string value on the page, I set the value and selected index of each control to the data that
2
3024
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2 or more user controls dynamically by adding to a placeholder defined in page_load. I've included the sample code for how we are accessing one. The user controls are not rocket science - just a few text boxes with public accessor properties. We've...
1
1798
by: Andrew | last post by:
Hi, friends, This drove me nuts: I had two web user controls: header.ascx and copyright.ascx. I planed to put them on each .aspx pages: Header on the top, and Copyright at the bottom. However, I could NOT place them in the correct positions of the .aspx pages. The header.ascx, copyright.ascx, and contents of .aspx kept OVERLAP each other. For example, in the following .aspx, the two web user controls
3
4097
by: Hrrglburf | last post by:
This is driving me nuts... Anyone have a clue why when a user control is focused, this.Focus(), that child controls under the same container do not get redrawn/updated? am I the only one experiencing this?
3
3012
by: craigkenisston | last post by:
Hi, I have some controls with these: <%@ OutputCache Duration="500" Shared="true" VaryByParam="None" %> However, I need that under certain user action, specifically, changing a value on a dropdownlist with auto-postback, the cache for the control be cleaned and the content regenerated. Is there a way to do this ?
0
2192
by: robgallen | last post by:
I have 2 user controls within a master page, and I would like one of them to call a function in the other. All the examples I have seen involve a page communicating with the Master page, or with a user control communicating with the Master page, not with a user control directly talking to another user control, bypassing the page itself. So, I have the following files: Haep.master - which contains:
7
1568
by: Dave | last post by:
I'm stuck on something and I've been trying to find some examples on it. I'm trying to show the data to my users as such: year1 year2 Q1 Q2 Q1 Q2 Smith my dataset looks like this: <?xml version="1.0" standalone="yes"?> <NewDataSet>
0
9492
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
9299
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
10076
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
9908
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8744
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
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
3
2702
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.