Failed to load viewstate with Custom WebControl

Discussion in 'ASP .Net Web Controls' started by Andrew Winn, Jan 15, 2004.

  1. Andrew Winn

    Andrew Winn Guest

    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
    Andrew Winn, Jan 15, 2004
    #1
    1. Advertising

  2. Andrew Winn

    Teemu Keiski Guest

    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.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Andrew Winn" <> wrote in message
    news:04bf01c3db75$a545d6a0$...
    > 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
    Teemu Keiski, Jan 15, 2004
    #2
    1. Advertising

  3. Andrew Winn

    Andrew Winn Guest

    Solved It.

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

    Cheers,
    Andrew

    >-----Original Message-----
    >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.
    >
    >--
    >Teemu Keiski
    >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >"Andrew Winn" <>

    wrote in message
    >news:04bf01c3db75$a545d6a0$...
    >> 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

    >
    >
    >.
    >
    Andrew Winn, Jan 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. venky

    Page Load and webcontrol page load

    venky, Jul 6, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,095
    venky
    Jul 11, 2005
  2. sck10
    Replies:
    6
    Views:
    909
    sck10
    Sep 1, 2006
  3. Josema
    Replies:
    2
    Views:
    345
  4. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    175
    Fabricio
    Sep 21, 2005
  5. Josema
    Replies:
    0
    Views:
    206
    Josema
    May 9, 2005
Loading...

Share This Page