Trouble with viewstate in usercontrols with 6.2
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.Controls09.10. public partial class Test : System.Web.UI.UserControl11. 12. protected void Page_Load(object sender, EventArgs e)13. 14. theVal.Text = MyVal;15. 16. 17. protected string MyVal18. 19. get20. 21. if (ViewState["MyVal"] == null)22. ViewState["MyVal"] = "Viewstate null";23. return (string)ViewState["MyVal"];24. 25. set26. 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" />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
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.