multiple dynamic controls with properties

R

Rubble

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
 
J

Jim Corey

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=en&lr=&ie=UTF-8&oe=UTF-8&selm=O8RSb.1
985%24HO2.1960%40news.edisontel.com

Jim
 
R

Rubble

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top