473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

UserControl and ViewState Error

Tim
Greetings!

I have a UserControl. On this UserControl is a Panel and a
RadioButtonList. The Panel's Visible property is set to false by
default. When the user selects a particular RadioButtonList value, a
postback is performed and the Panel's Visible property is set to true.
Selecting a different RadioButtonList value sets the Visible property
to false again.

So far, so good. It does, in fact, do this.

The UserControl is one of many that are loaded into a Page. I load all
of the UserControls in using LoadControl during the Page's Init event
(as I'm told I must do by several other articles posted to Usenet). On
the Page is a PlaceHolder and a DropDownList. Depending on the
selection of the DropDownList, the appropriate UserControl is added to
the Placeholder's Control collection, thus making that UserControl
visible to the user.

Switching between the UserControl's also works.

The problem I'm having arises when the selection of the DropDownList
displays the aforementioned UserControl (the one with the
RadioButtonList and Panel) and the user selects the RadioButtonList
option that make the hidden Panel visible. If the user then changes
which UserControl is to be visible via the DropDownList, I receive the
following error:

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.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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.

And the stack trace...

I know why the error occurs. What I need to know is how do I prevent
it from occurring. Would any of you fine Usenet folks be able to
assist me?

I'm afraid I'm not too familiar with ViewState and any tutorials,
guides, and other forms of assistance that say it is easy to use
completely fail to describe it adequately. Please keep this in mind
before posting back that "It's easy. All you have to do is change the
ViewState to...".

Thanks.

Nov 19 '05 #1
1 3439
Tim wrote:

I'm afraid I'm not too familiar with ViewState and any tutorials,
guides, and other forms of assistance that say it is easy to use
completely fail to describe it adequately. Please keep this in mind
before posting back that "It's easy. All you have to do is change the
ViewState to...".


A dropdown does not persist its value via Viewstate. It uses the
IPostBackDataHandler interface. Therefore, you should investigate whether
you even need Viewstate at all.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cederstrom | last post by:
Hello Group, I have created an ASP.NET page. The page consist of the following items: - Button A - Button B - UserControl When I press Button A, I execute the following code: ViewState =...
1
by: Ben Fidge | last post by:
As the Web UserControl class has no DesignMode property (it's not derived from Component), how do you tell if your UserControl is running in the IDE. I've got a public property on my UserControl...
3
by: Mike Dole | last post by:
I experimented with a usercontrol (TagedTextbox), I added a tag property. The tag value however is not persisted on postback (text value's fine)? I worked around it with: Me.ViewState("tag")...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
0
by: Matt Howeson | last post by:
I have a problem with a usercontrol that is dynamically loaded, from a web control and is not restoring it's viewstate properly. Here's the scenario. Within our content management system, I have...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
2
by: Grant Merwitz | last post by:
I am using usercontrols to control the contant in my website. Currently, depending on a parameter passed in the querystring, the appropriate usercontrol will be loaded. i.e. private void...
3
by: s.bussing | last post by:
Hi, does anyone have an Idea if it's possible to add a UserControl (containing serveral other controls like textboxes and/or dropdownlists) to an ArrayList? If I just put at the top of the...
2
by: Jav | last post by:
ASP.Net 2.0 - using ObjectDataSources (Csla) I sometimes have multiple Views (or Wizards) on a Page. Some of these may have UserControls with Addresses or Phones in GridViews belonging to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.