Trouble with viewstate in usercontrols with 6.2

Posted by Community Admin on 04-Aug-2018 06:23

Trouble with viewstate in usercontrols with 6.2

All Replies

Posted by Community Admin on 22-Nov-2013 00:00

I am working on building a custom widget and am unable to track viewstate properly. I have tried this in a custom user control and a widget created with Thunder. I originally noticed the issue when trying to use the RadGrid and I was unable to get any sorting or paging to work correctly when using the needdatasource event. I then created the user control below to test viewstate. What I found was that when I put a value in the text box it would populate the viewstate property and the value would be written to my label but if I posted back the page again the value in the viewstate property would be cleared. I did make sure that viewstate was enabled in the properties of the sitefinity page that I loaded the widget onto and also turned off cache just for testing. Please let me know what I need to do in order to get viewstate working.

CS File

01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.UI;
06.using System.Web.UI.WebControls;
07. 
08.namespace SitefinityWebApp.Controls
09.
10.    public partial class Test : System.Web.UI.UserControl
11.    
12.        protected void Page_Load(object sender, EventArgs e)
13.        
14.            theVal.Text = MyVal;
15.        
16. 
17.        protected string MyVal
18.        
19.            get
20.            
21.                if (ViewState["MyVal"] == null)
22.                    ViewState["MyVal"] = "Viewstate null";
23.                return (string)ViewState["MyVal"];
24.            
25.            set
26.            
27.                ViewState["MyVal"] = value;
28.            
29.        
30. 
31.        protected void update_Click(object sender, EventArgs e)
32.        
33.            MyVal = newVal.Text;
34.            theVal.Text = MyVal;
35.        
36.    
37.

Ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="SitefinityWebApp.Controls.Test" %>
<asp:Label ID="theVal" runat="server" Text="Wasn't Set" />
<br />
<asp:TextBox ID="newVal" runat="server"  />
<br />
<asp:Button ID="update" runat="server" Text="Update" OnClick="update_Click" />
<br />
<asp:Button ID="post" runat="server" Text="Post" />

Posted by Community Admin on 22-Nov-2013 00:00

Hi David,

We answered to your ticket regarding the same issue. If you find the solution useful you can share it with the community.

Regards,
Strahil Strahilov
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 07-Jan-2014 00:00

After a bit of troubleshooting we eventually discovered that viewstate does not work in preview mode which is where i was working from. After publishing the page and view the live version everything works. Apparently this is by design. 

This thread is closed