Failed to load viewstate

A

Adam222

hey there all..

I have a page with a DataList in it
on the DataList_ItemDataBound functio
I add a few
LiteralControl lit = new LiteralControl(html)
the HTML contains only "<img src='photo/111.jpg'>
the loading is fine

but when I try to PostBack the page to the Server, I get this 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.

I tried to remove this items(ViewState.Remove("lit");) - did not wor
I tried to make DisableViewState(lit.EnableViewState=false; and EnableViewState=false;) - did not help o
did not post back the other object on the page to the server

what can I do, to still postBack the items to the server & not get this error
10x Ada
 
T

Teemu Keiski

Hi,

as the error states, you need to add the same control similarly (in same
order) on postback. If this does not help you, post some more of your code.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke



Adam222 said:
hey there all...

I have a page with a DataList in it,
on the DataList_ItemDataBound function
I add a few:
LiteralControl lit = new LiteralControl(html);
the HTML contains only "<img src='photo/111.jpg'>"
the loading is fine,

but when I try to PostBack the page to the Server, I get this 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."
I tried to remove this items(ViewState.Remove("lit");) - did not work
I tried to make DisableViewState(lit.EnableViewState=false; and
EnableViewState=false;) - did not help or
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top