By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,441 Members | 1,831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,441 IT Pros & Developers. It's quick & easy.

multiple dynamic controls with properties

P: n/a
Hello,

Ive searched all over the net trying to find an answer to this...so
anybody with some expertise in this area would be greatly appreciated.

Background:
I have a webform that loads a datagrid. This datagrid has a button in
a column that loads another datagrid(user control) when clicked. This
new grid also has a column with a button that loads another user
control. So, there could be 3 user controls on this form if all the
buttons are pushed.

Problem:
The first two controls load fine...but when the button is pushed on
the second control, it disappears and only the first control loaded
onto the page is left. I know this happens due to the way asp.net
loads controls, etc.

Question:
How do I get this to work, so that I can dynamically load as many
controls as I want on the page, as well as set properties for the
controls?
Code Issues:
Each control loaded on the page has its own properties that are set in
the button event. For example, the second control loaded on the page
has an itemid property that is set when the first control runs the
button event. That button event from the first control basically runs
the following code:

public void showItem(object
sender,System.Web.UI.WebControls.CommandEventArgs e)
{

//create a control for item info
Control ctrl = new Control();
string szID = e.CommandArgument.ToString();
//its an asset
ctrl = (Inventory.Controls.assetinfo) LoadControl
(Request.ApplicationPath + Path.AltDirectorySeparatorChar +
"Controls/assetinfo.ascx");
((Inventory.Controls.assetinfo)ctrl).ItemID = szID;
phItemInfo.Controls.Add(ctrl);
}
That control also has a similar method to load a control to show user
information.
**How can I dynamically load the controls...and set their properties,
so that each control remains on the page? Ive tried using the
viewstate, sessions, etc., but nothing seems to allow me to load all
three of these controls while still being able to set their
properties.

Let me know if I need to provide any more info. Thanks again for any
ideas!

x B. Rubble x
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


B.,

As you may have found, you have to keep track
of what controls you have loaded and load them again
when a postback occurs.

This might be kind of involved in your scenario.
If you have a limited number of different controls you
might want to have them hard-coded on the page and
just make them visible as needed.

Also consider this:
http://groups.google.com/groups?hl=e...8&selm=O8RSb.1
985%24HO2.1960%40news.edisontel.com

Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

P: n/a
Thanks for the reply!

I tried the link you provided but it didnt solve the issue,
unfortunately. Ive thought about preloading all the controls on the
page and making them visible when needed, but the controls have
properties, so Im not sure how to load the control before I know what
its property value will be.

Ive also tried to store the controls in a databag of sorts which works
to some degree but still has issues...mostly viewstate issues it
appears.

Seems like there should be an easy way to do this, but Ive asked all
the experts where I work, and they cant seem to come up with a
solution that is scaleable.

Any MVPs out there seen this kind of issue???

Thanks again!

Jim Corey <jc****@nospamcharter.net> wrote in message news:<#d**************@tk2msftngp13.phx.gbl>...
B.,

As you may have found, you have to keep track
of what controls you have loaded and load them again
when a postback occurs.

This might be kind of involved in your scenario.
If you have a limited number of different controls you
might want to have them hard-coded on the page and
just make them visible as needed.

Also consider this:
http://groups.google.com/groups?hl=e...8&selm=O8RSb.1
985%24HO2.1960%40news.edisontel.com

Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.