View Full Version : [CLOSED] User Control ViewState

Jul 11, 2014, 12:06 PM
we have problem with user control viewstate in Ext 2.5.2, it get lost with DirectMethod call.
below are our test case:
user control :

<%@ Control Language="C#" %>
<script runat="server">
public string LabelText { get { return Convert.ToString(ViewState["LabelText"]); } set { ViewState.Add("LabelText", value); } }
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
ResourceManager resourceManagerControl = ResourceManager.GetInstance();
if (resourceManagerControl == null) { throw new Exception("missing ResourceManage"); }
resourceManagerControl.AddAfterClientInitScript(th is.BuildScript());

private string BuildScript()
return string.Format(@"App.direct.{0}.GetLabelValue({{success:function(re sult){{{1}.setText(result);}}}});", this.ClientID, this.LblUserControlTest.ClientID);

public string GetLabelValue()
return this.LabelText;
<ext:Label ID="LblUserControlTest" runat="server"></ext:Label>

WebForm Code:

<%@ Page Language="C#" %>

<%@ Register Src="~/BAM/ViewStateTest.ascx" TagPrefix="uc1" TagName="ViewStateTest" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
ViewStateTest.LabelText = "Hello World";
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" AjaxViewStateMode="Enabled" EnableViewState="true" ViewStateMode="Enabled" />
<ext:Viewport ID="ViewPort1" runat="server">
<uc1:ViewStateTest runat="server" ID="ViewStateTest" ViewStateMode="Enabled" EnableViewState="true" />

the UserControl ViewState "LabelText" will be null on directmethod request.
NOTE that the same example with Ext 1.x work perfectly even without AjaxViewStateMode="Enabled" EnableViewState="true" ViewStateMode="Enabled".(of course we change App.direct to Ext.net.DirectMethods)
does we miss something?
Thank you.

Jul 11, 2014, 4:57 PM
Hi @snow_cap,

Please search for "ViewState" here in this document.

Jul 11, 2014, 6:29 PM
thank you, it worked