Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
Loadcontrol and viewstate question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="jhewitt, post: 453104"] It seems the problem is this: When you load a user control onto the page the control 'values' are stored in viewstate. When the page reloads, the user control no longer exists (just its viewstate). When a new control is loaded in the old controls place, it can't negotiate the old controls viewstate so the app clocks. I Had the same problem I would try to use a 'main page' and have it load different user controls into its 'content' section. I'll quickly describe what I'm talking about so you will get a better idea of what I did. My main page has a 'loadContent' procedure. This procedure gets a control name from session and loads that control into a panel. When a user clicks a button on the user control, the code behind the user control sets the session variable to a new control name and everything posts back. On the post back, the main page runs 'loadContent' and gets the new control name from session. Loading this new control causes the app to crash. My Solution I added another session variable called 'loadedControl'. Now when the main page's 'loadControl' method is called, if the control name sent to it differes from the value in 'loadedControl', the previously loaded user control is reloaded (assuming it's viewstate) and removed (removing its viewstate with it). Then the new user control is loaded into the panel on the main page. See my 'loadedControl' procedure in VB below: Public Sub loadContent(ByVal controlName As UserControls.enumContent) Me.pnlContent.Controls.Clear() ' just in case ' adds the previously loaded control, if different from the one sent, and removes it to clean up viewstate If controlName <> GlobalVariables.loadedContent Then Me.pnlContent.Controls.Add(UserControls.content(GlobalVariables.loadedContent)) Me.pnlContent.Controls.Remove(Me.pnlContent.Controls(0)) End If ' loads sent control Me.pnlContent.Controls.Add(UserControls.content(controlName)) ' sets the global variable name for the finally loaded control GlobalVariables.loadedContent = controlName End Sub [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
Loadcontrol and viewstate question
Top