473,324 Members | 2,166 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,324 software developers and data experts.

Failed to load viewstate

et
I. 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.

Source Error:

Line 70: 'do we want to clear controls???

Line 71: me.ph.Controls.clear

Line 72: me.ph.Controls.Add(me.oCtrlDemo)

Line 73: End Sub

Line 74:


On my default page, I have a treeview and when the user clicks an item, it
selects a control to load into a placeholder. I get this error after a
couple of clicks around, what am I doing wrong, I am clearing the controls,
and I even tried loading only if not postback, then tried reloading every
time... This is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

'if not ispostback then

me.ph.Controls.clear

DoTheLoad()

'end if

End Sub

Public Sub tvwMenu_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tvwMenu1.SelectedIndexChanged

intSelectedMenu = e.newnode.tostring

me.ph.Controls.clear

DoTheLoad(intSelectedMenu)

End Sub

Private Sub DoTheLoad(Optional i as string = "")

select case i

Case "0.0"

me.oCtrlDemo = LoadControl("Controls\ctl1.ascx")

Case "0.2"

me.oCtrlDemo = LoadControl("ctl2.ascx")

Case else

me.oCtrlDemo = LoadControl("Controls\ctlDefault.ascx")
End Select

me.ph.Controls.clear

me.ph.Controls.Add(me.oCtrlDemo)

End Sub
Nov 19 '05 #1
1 6504
Hi,
Do you need ViewState enabled? If not try one of theese:
1. Set the ph object EnableViewState property to False
2. Set the DOCUMENT EnableViewState property to False

You need ViewState enabled if you change control properties like font, color
etc. (but not, for example, Text on a TextBox) in code and need to persist
them through post-backs. Otherwise, you may disable ViewState and it has the
added benefit of reducing payload sizes - especially if you have DataGrids.

"et" wrote:
I. 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.

...

Nov 19 '05 #2

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

Similar topics

3
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed...
0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
1
by: rockdale | last post by:
Sometime my ASP.NET application got this error message but not always everytime. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that...
6
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page...
2
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView...
0
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the...
2
by: Rotsey | last post by:
Hi, I have a web site that uses user controls to display different formats of timesheets. I have a browse page that has prev/next buttons to browse through a set of timesheets. As I say...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.