+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / No Viewstate

No Viewstate

57 posts, 0 answered
  1. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    10 Jan 2011
    Link to this post
    I know this has been covered before, but the proposed solution does not work for me.

    On postbacks, I'm losing the values in my dropdown lists (and other things I set in the Page_Load event when the page is first loaded). Below is an example (I'm getting values from a DB) of what I'm doing. The Page_Load event is in a custom control. The OnInit override is in my MasterPage (template). If I look at the IsViewStateEnabled or EnableViewState properties, they look good.

    I've also tried setting ViewStateMode in the MasterPage and control to "Enabled" with no luck.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlNumbers.DataSource = Enumerable.Range(1, 10);
            ddlNumbers.DataBind();
        }
    }
     
    protected override void OnInit(EventArgs e)
    {
        Page.EnableViewState = true;
        base.OnInit(e);
    }

    Any suggestions?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jan 2011
    Link to this post
    Hi Eric,

    You might find this post useful.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    10 Jan 2011
    Link to this post
    This seems to be all about backend pages (which I assume are the pages under the /Sitefinity folder). I'm not worried about those. I'm struggling getting the frontend pages (e.g. my homepage) to maintain their values in the viewstate. Everybody seems to say the line "Page.EnableViewState = true" works for them, but for me it's not.

    I added in some testing code just to test out the ViewState. I check to see if there's a "Now" value in the ViewState, if there isn't, I put the current time into the ViewState. I then output the value. On the initial load, it prints the current time. When my custom control does a postback, a new time gets outputted, which makes me think the ViewState isn't working.

    protected override void OnInit(EventArgs e)
    {
        Page.EnableViewState = true;
     
        if (ViewState["Now"] == null)
        {
            ViewState["Now"] = DateTime.Now.ToLongTimeString();
        }
     
        Response.Write(ViewState["Now"]);
     
        base.OnInit(e);
    }
  4. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    10 Jan 2011
    Link to this post
    Hi Eric,

    I'm having the exact same issue with my implementation and I tried turning the ViewState on in 3 locations...web.config, the page itself, and the actual control. None of the options worked for me either.
  5. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    11 Jan 2011
    Link to this post
    Yeah, I tried the web.config, the page directive of the master page, the control directive of the user control, overriding the OnInit event of the master page, overriding the OnInit event of the user control.

    It's working for other people?
  6. John S.
    John S. avatar
    126 posts
    Registered:
    09 Aug 2004
    11 Jan 2011
    Link to this post
    Hello Eric,

    This is a master page that worked for me. Hopefully, it helps.

    John

    <%@ Master Language="C#" AutoEventWireup="true" %>
    <script type="text/C#" runat="server">
        protected override void OnInit(EventArgs e)
        {
            this.Page.EnableViewState = true;
            base.OnInit(e);
        }
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head runat="server">
        <title></title>
    <style type="text/css">  
        html, body, form  
        {  
            height: 100%;  
            margin: 0px;  
            padding: 0px;  
            overflow: hidden;  
        }  
        </style
           </head>
    <body>
        <form runat="server">
    <asp:ContentPlaceHolder ID="PageMenu" runat="server"></asp:ContentPlaceHolder>
                <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        </form>
    </body>
    </html>


  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Jan 2011
    Link to this post
    Hello John,

    Thanks for your input here.

    For the official release there will be an option to enable the ViewState for each page from the UI, so I believe that nobody will have issues with this.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    11 Jan 2011
    Link to this post
    Hey John,

    Thanks for sharing that code...that's working for me on most pages now and will do until the final release of 4.0.

    The only thing I haven't got it to work for is drag and drop between 2 RadGrids.
  9. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    11 Jan 2011
    Link to this post
    So I looked at the HTML source of the page and the ViewState is there. Decoding it showed the values I was expecting.

    But my databound controls (e.g. dropdown lists and repeaters) still lose their values. Again, the EnableViewState = true in the init event didn't do anything. Will the page property still fix my issue since the ViewState seems to be working; it's working, but my controls aren't getting values from the ViewState.

    In a standard web application with ASPX pages, it works fine.

    Thanks,
    Eric
  10. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    11 Jan 2011
    Link to this post
    OK, I think I figured it out. The ViewState is working, but when I put a control in a Layout control, my databound controls lose their values after a postback.

    I have a base template based on a masterpage. If I put my control in the template directly, it works. If I add a layout control and put my control inside the layout, it doesn't work.

    I tried to fix it by having my control set its parent's viewstate property (and it's parent's parent and it's parent's parent's parent, etc) which didn't fix it. I also tried to have my master page recursively set it and its child controls to enable the viewstate; again no luck. I also tried to set enable_view_state = 1 on my master page in the sf_page_templates table, again nothing. I then set enable_view_state on sf_page_data and again nothing.

    I wonder how these layouts work and how they interfere with the controls.

    Hopefully the discussed option to set the ViewState per page fixes this issue or this is fixed for the official release.
  11. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    11 Jan 2011
    Link to this post
    Eric,

    I concur with your findings. The drag and drop table that I couldn't get to work after applying the master page fix that John posted is in a layout template that divides the page into 25% / 75% columns.
  12. Pavel Iliev
    Pavel Iliev avatar
    140 posts
    Registered:
    18 Jul 2016
    21 Jan 2011
    Link to this post
    Hi Eric,

    We've reproduced the issue at was logged as a bug (#105496). We'll try to fix it for SP1. I am sorry for the inconvenience that this might have caused you.

    Regards,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Lorne
    Lorne avatar
    38 posts
    Registered:
    04 Nov 2010
    24 Jan 2011
    Link to this post
    I have a control which requires ViewState.
    I have put this control into the Sitefinity toolbox.
    I have created a page and added the control from the toolbox to it.
    My controls lose their values on postbacks. (I have tried the suggestion of using my own master page and called EnableViweState = true. This does not prevent me from losing values.)

    The previous post mentions a bug. I don't know if that bug is relevant to my problem or not.

    Please, Telerik, tell me, am I able to use ViewState for a control I've created and added to the toolbox, or not?
    If the answer is yes, please tell me precisely how to do it.

    Thank you.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Jan 2011
    Link to this post
    Hi Eric,

    We are investigating the issue and I hope that it will be fixed in one of the next internal builds that we have each Friday.
    Currently you can get the ViewState workign if you declare the controls inside your .master file, but this means that you cannot edit them through Sitefinity's page editor.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  15. JV
    JV avatar
    74 posts
    Registered:
    15 Jun 2012
    25 Jan 2011
    Link to this post
    Hi,

    I have the same problem. If i drag and drop to master page it works if i drag and drop to one custom layout my control loses the viewstate.

    But another strange thing happens. If i drag one "Content block" before my control de viewstate of my control starts to work. If i remove the "control block" the viewstate fail again.

    I hope this be resolved soon.
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Jan 2011
    Link to this post
    Hello,

    Yes the team is working on this issue. It is with high priority and I hope that we will manage to fix it by the end of the week.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  17. Lorne
    Lorne avatar
    38 posts
    Registered:
    04 Nov 2010
    10 Feb 2011
    Link to this post
    I have a front-end page for which I checked the "Enable ViewState" checkbox.

    However, ViewState is not working on that page. (Or more specifically, on my controls that are on that page.)

    I am using version 4.0.1098.0

    Please, can you tell me if this is still a problem that has not been fixed. Or can you please tell me what to do to simply enable ViewState on my front-end page.

    (I am extremely frustrated by this. I don't know why something this simple and this common is so hard to get working.)

    Thank you.
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2011
    Link to this post
    Hello,

    We keep working on the issue. Its current status is not done. It turned out that the fix is not something trivial and we will need more time to sort out the problem properly.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  19. Rick
    Rick avatar
    12 posts
    Registered:
    21 Sep 2007
    17 Feb 2011
    Link to this post
    I had this same problem today and found a work around that works for my case - maybe yours too.
     
    In my case, my pages use a Master Page file as a template (I'm migrating existing design from SF 3.7 and not using layout controls at all).

    Enabling ViewState on my master page fixed this issue for me.

    <%@ Master Language="C#" EnableViewState="true" %>

    Hope this helps some until a fix is released.
  20. Lorne
    Lorne avatar
    38 posts
    Registered:
    04 Nov 2010
    24 Feb 2011
    Link to this post
    Unfortunately, the master page fix doesn't work for me.
  21. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    24 Feb 2011
    Link to this post
    Are you using templates (i.e. column templates)? I don't think there's a workaround for controls in the templates. If you take your control out of a template, the workarounds should work -- at least mine does.
  22. Lorne
    Lorne avatar
    38 posts
    Registered:
    04 Nov 2010
    24 Feb 2011
    Link to this post
    I create a new page and for its template I select my own master page. Then I put my user control onto this page. The ViewState doesn't work.

    I can only get ViewState to work when I create my own aspx page. 
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Feb 2011
    Link to this post
    Hi Eric,

    The issue with the View State is still not fixed. We keep working on it.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
  24. Greg Figueroa
    Greg Figueroa avatar
    23 posts
    Registered:
    24 Apr 2005
    03 Mar 2011
    Link to this post
    Hello Ivan,

    It's been a week since the last post, and Sitefinity 4.0 SP1 has come and gone and there is still no resolution.

    Can you provide an update on the progress regarding this issue? 

    This issue is also suspiciously missing from PITS.

    Thanks, Greg
  25. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    04 Mar 2011
    Link to this post
    I'd like to add my voice to this. 

    Not being able to use Viewstate from Page_Load has turned into a huge issue for us, potentially requiring a lot of kludgey workarounds.

    Ivan, if you could please let us know if this is fixed in a weekly build, or if it's scheduled for Q1, it would help all of us schedule development and possibly discuss this with our clients.

    Thanks.

    - William
  26. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Mar 2011
    Link to this post
    Hello William,

    The fix should be available in Q1 release. I agree that this is really frustrating and we are doing our best to fix the problem ASAP. We are changing some basic code related to the page lifecycle and this is quite difficult. I will update the post if the issue is fixed before the Q1 release, so you ca get an internal build. I am sorry for the inconvenience.

    Regards,
    Ivan Dimitrov
    the Telerik team
  27. Greg Figueroa
    Greg Figueroa avatar
    23 posts
    Registered:
    24 Apr 2005
    04 Mar 2011
    Link to this post
    Ivan,

    Can you at least add this issue into PITS?  I'd rather see it tracked there, then here in this forum post.

    Do I need to open a ticket to get it there?  I have to believe that there a boatload of other customers that already have tickets open for this issue.

    Thanks, Greg
  28. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Mar 2011
    Link to this post
    Hi Greg ,

    The issue is logged with ID 4968 - RadGrid problem with the life cycle on postback

    All the best,
    Ivan Dimitrov
    the Telerik team
  29. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    07 Mar 2011
    Link to this post
    What about the original issue in the thread? No viewstate (until PreRender I think) when controls are in (column) layouts?

    Is that in PITS? Should I go add it?
  30. Lorne
    Lorne avatar
    38 posts
    Registered:
    04 Nov 2010
    07 Mar 2011
    Link to this post
    You've logged this as a RadGrid problem?

    Isn't this a general ViewState problem?
57 posts, 0 answered
1 2