Failed to load viewstate with Custom WebControl

A

Andrew Winn

Hi,

I have created a WebControl which contains an ASP
Textbox, ASP Button, ASP Listbox and a Hidden field.
I've been using "Building ASP.NET Server Controls" by
Dale Michalk and Rob Cameron as a reference.
My code is in VB.NET

It works in my example page which has a couple of
controls and a button to post back.

But when I put it on a page which I have already created
with lot's of other controls on it I get the following
message when it post's back (it works on initial load).
I also get the same message even if I've only draged the
control onto the form without any server-side coding. If
I remove the control the Page works Ok.

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

Can anybody give me an advice about this?

Regards,
Andrew
 
T

Teemu Keiski

Hi,

as the error describes, are you sure the control is added to the same index
position between initial request and postback? Post some sample code.
 
A

Andrew Winn

Solved It.

In the SaveViewState function I incorrectly typed
if .. = Nothing
when it should be
if .. Is Nothing

Cheers,
Andrew
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top