Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

Discussion in 'ASP .Net Web Controls' started by Denny Smolinski via .NET 247, May 4, 2004.

  1. I have been searching forever. Here is my problem.

    I have form of 3 panels of information for car insuranceinformation.

    1st panel is general information but I need to retrieve theNUMBER OF FAMILY members to see how many names I need for mynext panel that is dynamically generated based upon my drop downlist selection. I can generate panel 2 with the number of namesI need but the problem is then posting the data from thetextboxes to the next page.

    ERROR: Object reference not set to an instance of an object.

    I try to retrieve from a dynamic box txt1, txt2, etc. I havetried creating the boxes on the fly and even in the page_initsection and just set visible = false. Please if anyone couldhelp. Thank you

    --------------------------------
    From: Denny Smolinski

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>GcCBM0LoGUWK0X3cuePCRA==</Id>
     
    Denny Smolinski via .NET 247, May 4, 2004
    #1
    1. Advertising

  2. Denny Smolinski via .NET 247

    Eidolon Guest

    One mistake that drove me batty at first with dynamic controls and
    apparently is a very common mistake from what i saw online is this...

    In order to get anything out of your previous control, you MUST add it back
    into the control heirarchy at EXACTLY the same place (this is where the
    placeholders come in handy) as it was before, otherwise the framework will
    not be able to repopulate it all. Here is the way i do this. This has worked
    flawlessly and beautifully for me.
    In my page i put the following:

    I add a Literal control named "ltlLastControl", and set the Text property to
    the path for my first/default ascx file.
    I add a PlaceHolder control named "bucket".

    In my Page_Load I add the following code as the first line:
    <code>
    If Me.LastControl <> "" Then SwapControl(Me.LastControl)
    </code>

    Then i also add the following code to my page:
    <code>
    Protected ReadOnly Property LastControl() As String
    Get
    Return ltlLastControl.Text
    End Get
    End Property

    '// NewControl receives the ASCX path to load
    Protected Sub SwapControl(ByVal NewControl As String)
    Dim ctl As Web.UI.Control = LoadControl(NewControl)

    bucket.Controls.Clear()
    bucket.Controls.Add(ctl)

    ltlLastControl.Text = NewControl
    End Sub
    </code>
     
    Eidolon, May 4, 2004
    #2
    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. msnews.microsoft.com
    Replies:
    1
    Views:
    478
    =?Utf-8?B?Q2hyaXMgTW9oYW4=?=
    Sep 26, 2004
  2. John Mason

    Retrieve htmlbutton ID from placeholder

    John Mason, Jan 21, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    443
    John Mason
    Jan 22, 2005
  3. Kees de Winter
    Replies:
    3
    Views:
    993
    Karl Seguin [MVP]
    May 12, 2006
  4. Phuff
    Replies:
    2
    Views:
    566
    Phuff
    Nov 3, 2006
  5. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    361
Loading...

Share This Page