multiple dynamic controls with properties

Discussion in 'ASP .Net' started by Rubble, May 11, 2004.

  1. Rubble

    Rubble Guest

    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
     
    Rubble, May 11, 2004
    #1
    1. Advertising

  2. Rubble

    Jim Corey Guest

    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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Jim Corey, May 11, 2004
    #2
    1. Advertising

  3. Rubble

    Rubble Guest

    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 <> wrote in message news:<#>...
    > 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
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Rubble, May 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald
    Replies:
    2
    Views:
    853
    Robbe Morris [C# MVP]
    Jan 17, 2006
  2. Praveen Ramesh

    Specifying dynamic default values for properties in custom controls:

    Praveen Ramesh, Sep 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    132
    Praveen Ramesh
    Sep 2, 2004
  3. aesquivel
    Replies:
    0
    Views:
    147
    aesquivel
    Jun 10, 2005
  4. Igor Belagorudsky

    expando/dynamic properties in user controls

    Igor Belagorudsky, Aug 6, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    132
    Igor Belagorudsky
    Aug 6, 2003
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    473
    Eidolon
    May 4, 2004
Loading...

Share This Page