PDA

View Full Version : [CLOSED] User Control ViewState



snow_cap
Jul 11, 2014, 12:06 PM
Hello,
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);
}

[DirectMethod]
public string GetLabelValue()
{
return this.LabelText;
}
</script>
<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">
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewStateTest.LabelText = "Hello World";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" AjaxViewStateMode="Enabled" EnableViewState="true" ViewStateMode="Enabled" />
<ext:Viewport ID="ViewPort1" runat="server">
<Content>
<uc1:ViewStateTest runat="server" ID="ViewStateTest" ViewStateMode="Enabled" EnableViewState="true" />
</Content>
</ext:Viewport>
</form>
</body>
</html>


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.

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

Please search for "ViewState" here in this document.
http://examples2.ext.net/#/Getting_Started/Release_Documents/BREAKING_CHANGES/

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