PDA

View Full Version : How to enable view state for direct event?



galuset
Aug 19, 2010, 8:37 PM
Hi,

Here is my code:


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<ext:ResourceManager runat="server" ViewStateMode="Enabled" />
<ext:FormPanel EnableViewState="true" ViewStateMode="Enabled" runat="server">
<Buttons>
<ext:Button ID="SendUserName" Text="Send" runat="server" >
<DirectEvents>
<Click OnEvent="SendUserName_DirectClick" />
</DirectEvents>
</ext:Button>
</Buttons>
<Items>
<ext:HBoxLayout runat="server">
<BoxItems>
<ext:BoxItem>
<ext:TextField ID="UserName" runat="server" />
</ext:BoxItem>
<ext:BoxItem>
<ext:Label ID="InfoLabel" runat="server" Text="" />
</ext:BoxItem>
</BoxItems>
</ext:HBoxLayout>
</Items>
</ext:FormPanel>
</asp:Content>


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void SendUserName_DirectClick(object sender, DirectEventArgs e)
{
InfoLabel.Text = "User name set: " + (UserName.Text ?? "(no info)");
}
}

My problem: UserName.Text always equals "" (empty string). How to change this (enable view state)?

geoffrey.mcgill
Aug 20, 2010, 12:22 AM
Hi galuset,

You can set ViewStateMode="Enabled" on the DirectEvent config.

Example


<Click ViewStateMode="Enabled" OnEvent="SendUserName_DirectClick" />

Hope this helps.

galuset
Aug 20, 2010, 7:31 AM
Unfortunately this didn't help :(

Here is how my code looks like.


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<ext:ResourceManager ID="ResourceManager1" runat="server" ViewStateMode="Enabled" />
<ext:FormPanel ID="FormPanel1" EnableViewState="true" ViewStateMode="Enabled" runat="server">
<Buttons>
<ext:Button ID="SendUserName" Text="Send" runat="server" >
<DirectEvents>
<Click ViewStateMode="Enabled" OnEvent="SendUserName_DirectClick" />
</DirectEvents>
</ext:Button>
</Buttons>
<Items>
<ext:HBoxLayout ID="HBoxLayout1" runat="server">
<BoxItems>
<ext:BoxItem>
<ext:TextField ID="UserName" runat="server" />
</ext:BoxItem>
<ext:BoxItem>
<ext:Label ID="InfoLabel" runat="server" Text="" />
</ext:BoxItem>
</BoxItems>
</ext:HBoxLayout>
</Items>
</ext:FormPanel>
</asp:Content>

Maybe something is wrong with my Site.Master or Web.config...

Site.Master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ColliteTest.SiteMaster" %>

<!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>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<h1>Coolite test</h1>
<hr />
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</body>
</html>

Web.config

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\asp netdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false"/>
</httpHandlers>

<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
</httpModules>

<pages>
<controls>
<add tagPrefix="ext" namespace="Ext.Net" assembly="Ext.Net"/>
<add tagPrefix="ext" namespace="Ext.Net.Utilities" assembly="Ext.Net"/>
</controls>
</pages>

<compilation debug="true" targetFramework="4.0" />

<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>

<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>

<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>

</system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

galuset
Aug 20, 2010, 8:58 AM
Works! I have changed ext:FormPanel to standard form.

neosaint
Jul 11, 2014, 5:16 AM
Hi galuset,

Could you please share your codes? because I try to enabledviewstate, still doesn't work.

Thank you.