Dynamically loading user controls

J

Johnny Fugazzi

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top