Dynamically loading user controls

Discussion in 'ASP .Net' started by Johnny Fugazzi, Nov 24, 2004.

  1. Good morning,

    Background: I am working on a web that will display information about
    companies and contacts. I would like to have a details page that displays
    some basic details about the record that has been selected (works), and then
    have a table with a series of "tabs" that load additional details. I am
    using this approach to cut down on the number of pages needed.

    The "tabs" are a series of linkbuttons that clear a panel, and then
    dynamically add a specific usercontrol to a panel. The error I am getting
    when I do this is:

    "Failed to load viewstate. The control tree into which viewstate is being
    loaded must match the control tree that was used to save viewstate during
    the previous request. For example, when adding controls dynamically, the
    controls added during a post-back must match the type and position of the
    controls added during the initial request. "

    I have included example code for two of the "tab" buttons
    ---
    Private Sub btnAddressing_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnAddressing.Click
    resetTabs()
    'btnAddressing.Font.Size = FontUnit.Small
    btnAddressing.Font.Underline = True
    btnAddressing.ForeColor = Drawing.Color.DarkRed
    pnlDetails.Controls.Clear()
    Dim ctlAddresses As Control =
    LoadControl("companyDetailsAddresses.ascx")
    ctlAddresses.ID = "ctlAddresses"
    pnlDetails.Controls.Add(ctlAddresses)
    End Sub

    Private Sub btnCategoris_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnCategoris.Click
    resetTabs()
    'btnCategoris.Font.Size = FontUnit.Small
    btnCategoris.Font.Underline = True
    btnCategoris.ForeColor = Drawing.Color.DarkRed
    pnlDetails.Controls.Clear()
    Dim ctlCategories As Control =
    LoadControl("companyDetailsCategories.ascx")
    ctlCategories.ID = "ctlCategories"
    pnlDetails.Controls.Add(ctlCategories)
    End Sub
    ---

    Any help would be appreaciated.

    Thanks
     
    Johnny Fugazzi, Nov 24, 2004
    #1
    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. Ben Miller [msft]
    Replies:
    0
    Views:
    605
    Ben Miller [msft]
    Aug 5, 2003
  2. sonic_soul
    Replies:
    0
    Views:
    522
    sonic_soul
    Aug 14, 2003
  3. Nick Stansbury

    loading user controls dynamically

    Nick Stansbury, Jul 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    347
    John Saunders
    Jul 19, 2004
  4. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    507
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
  5. Bob Rock
    Replies:
    1
    Views:
    665
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
Loading...

Share This Page