LoadViewState not called in custom control

Discussion in 'ASP .Net Web Controls' started by Brad, Oct 6, 2004.

  1. Brad

    Brad Guest

    A custom control I have created overrides LoadViewState and SaveViewState.
    Problem is that my override of LoadViewState is not getting called: debugger
    breakpoint is not stopping at in it. The control is similar to panel
    control, it allows child controls to be added within it: so
    ParseChildren(False) and PersistChildren(True). Is there a limitation on
    LoadViewState when ParseChildern and PersistChildren are set as I have?
    Except for this problem the control works correctly.

    Brad
     
    Brad, Oct 6, 2004
    #1
    1. Advertising

  2. Hi Brad,

    Thanks for posting here. Regarding on this issue, I'll first do some tests
    on my side and I'll let you know my result as soon as possible. In
    addition, if you got any other finding during the time, please also feel
    free to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 7, 2004
    #2
    1. Advertising

  3. Brad

    Brad Guest

    I should also mention I do also override Trackviewstate. I know
    Trackviewstate executes before Loadviewstate....and as best I can tell
    adding my code to Trackviewstate will work. But I'd still like to know how
    to properly get my Loadviewstate override to execute....if it will with a
    panel type control..

    Brad

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Brad,
    >
    > Thanks for posting here. Regarding on this issue, I'll first do some tests
    > on my side and I'll let you know my result as soon as possible. In
    > addition, if you got any other finding during the time, please also feel
    > free to post here. Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
     
    Brad, Oct 7, 2004
    #3
  4. Hi Brad,

    Thanks for your followup. I've done a simple test on my side. Creating a
    webcontrol which applys the
    "ParseChildren(false)" and "PersistChildren(true)", but seems the
    LoadViewState and SaveViewState override methods still be entered. Here is
    the test control's code, you may also have a try to see whether the result
    on your side is the same, if so , I think we should focus on the particular
    control which suffering the problem:

    =====================
    [DefaultProperty("Text"), ParseChildren(false), PersistChildren(true),
    ToolboxData("<{0}:SimplePanel runat=server></{0}:SimplePanel>")]
    public class SimplePanel :
    System.Web.UI.WebControls.WebControl,INamingContainer
    {
    private string text;
    private string _controlname;


    public string ControlName
    {
    get
    {
    return _controlname;
    }
    set
    {
    _controlname = value;
    }
    }

    [Bindable(true),
    Category("Appearance"),
    DefaultValue("")]
    public string Text
    {
    get
    {
    return text;
    }

    set
    {
    text = value;
    }
    }

    protected override void LoadViewState(object savedState)
    {
    Triplet tpt = savedState as Triplet;
    _controlname = tpt.First as string;
    base.LoadViewState (tpt.Second);
    }

    protected override object SaveViewState()
    {
    Triplet tpt = new Triplet(_controlname,base.SaveViewState ());
    return tpt;
    }

    protected override void Render(HtmlTextWriter writer)
    {
    base.Render (writer);
    writer.WriteLine("<br>ControlName: " + this.ControlName);
    }
    }
    ======================

    If you have any other questions or finding, please also feel free to post
    here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 8, 2004
    #4
  5. Hi Brad,

    Have you got any further progress on this issue or have you got it
    resolved? If there're anything else we can help, please feel free to post
    here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Oct 12, 2004
    #5
  6. Brad

    Brian Noyes Guest

    I'm having the same problem with LoadViewState and SaveViewState not
    being called. I cut and pasted the code from your SimplePanel into a
    WebControl library and tried adding it to the page.

    The LoadViewState and SaveViewState methods never get called as
    evidenced by setting breakpoints in them in the debugger, and also if I
    change the ControlName property in the Load event handler only when not
    postback, it is apparent that the value is not being persisted through
    viewstate.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Brian Noyes, Oct 26, 2004
    #6
  7. Brad

    Brian Noyes Guest

    Disregard my previous post. The problem was that some knucklehead had
    slapped a web.config file in the root folder for the site that contained
    EnableViewState="false", so naturally the viewstate methods were not
    being called.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Brian Noyes, Nov 4, 2004
    #7
    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. SSW
    Replies:
    2
    Views:
    537
  2. SSW
    Replies:
    0
    Views:
    267
  3. SSW
    Replies:
    0
    Views:
    300
  4. Vishal
    Replies:
    0
    Views:
    408
    Vishal
    Apr 8, 2005
  5. Memi Lavi

    LoadViewState is not called

    Memi Lavi, Feb 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    152
    Alessandro Zifiglio
    Feb 8, 2004
Loading...

Share This Page