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

Dynamic Controls, Postbacks, ViewState, Oh My!

Hello,

I am loading several user controls dynamically in OnInit() like this:

ucListBoxSelections ucLocation =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

ucListBoxSelections ucDept =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

ucListBoxSelections ucBusiness =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

PlaceHolder1.Controls.Add(ucLocation);

PlaceHolder1.Controls.Add(ucDept);

PlaceHolder1.Controls.Add(ucBusiness);

Then, in the Page_Load I thought I should be able to access these Controls
and reload (or assign for the first time) its data through the ViewState
(that has not been lost because it was loaded in OnInit().

Am I doing this correctly because I cannot "find" these Controls in
Page_Load?

Also, each time I click on any one of these User Controls there is a
postback, as expected, but all the listboxes (in each of the user controls)
still seems slow to load. I assume that is because they are reloading. The
idea, I thought, was that it was faster to load these controls in OnInit.

I think I am close, does anyone have some suggestions?

Thank you.

p.s. There are several user controls that get loaded each time. However,
they do not have to be dynamic because they will always appear on the page.
It's just their data in their listboxes will change. Is there a better way
to approach this?
Sep 19 '06 #1
1 2334
Here is a starter article to read:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

This article describes the ASP.NET Page LifeCycle. It describes how
everything is built when you request an asp.net page and in what order.

IIRC, You should be able to access the controls in the Page_Load
method, at this point OnLoad is called and postback data is loaded into
the controls. So you should be able to.

I apologize for the vagueness of the post, its been a little while
since I've played with dynamic controls so my mind is a little fuzzy.

Take a look at that article though, that should point you in the right
direction.

Gummy wrote:
Hello,

I am loading several user controls dynamically in OnInit() like this:

ucListBoxSelections ucLocation =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

ucListBoxSelections ucDept =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

ucListBoxSelections ucBusiness =
(ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");

PlaceHolder1.Controls.Add(ucLocation);

PlaceHolder1.Controls.Add(ucDept);

PlaceHolder1.Controls.Add(ucBusiness);

Then, in the Page_Load I thought I should be able to access these Controls
and reload (or assign for the first time) its data through the ViewState
(that has not been lost because it was loaded in OnInit().

Am I doing this correctly because I cannot "find" these Controls in
Page_Load?

Also, each time I click on any one of these User Controls there is a
postback, as expected, but all the listboxes (in each of the user controls)
still seems slow to load. I assume that is because they are reloading. The
idea, I thought, was that it was faster to load these controls in OnInit.

I think I am close, does anyone have some suggestions?

Thank you.

p.s. There are several user controls that get loaded each time. However,
they do not have to be dynamic because they will always appear on the page.
It's just their data in their listboxes will change. Is there a better way
to approach this?
Sep 19 '06 #2

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

Similar topics

4
by: Tom Wisnowski | last post by:
Hello all, Here is a simple example of what I'm doing... Create a ASPX page Add a PlaceHolder(plch) and a Button(btn) to the page. In the code behind on Page_load add the following......
4
by: Chuck Ritzke | last post by:
Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of the best way to handle...
0
by: Perecli Manole | last post by:
I have a form that dynamicaly loads user controls based on user postbacks. Everything works well except that the framework seems to want to match the viewstate data from my previous control to the...
3
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As...
8
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the...
1
by: npverni | last post by:
I have a fairly complex form that needs to load and maintain the state of several different dynamic user controls. Here is the workflow: 1) A series of editable user controls (each containing...
1
by: Andrew Robinson | last post by:
I have a <asp:table> control with a large number of dynamically created LinkButtons. I am using the command event, command name and command argument values in my LinkButtons to trigger actions...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
5
by: Hans Kesting | last post by:
Hi, Is there good information about the asp.net page lifecycle in combination with dynamically loaded controls? Or on "how to build dynamic controls"? I keep hitting problems where values are...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.