[CLOSED] Possible bug: Viewstate doesn't persist

  1. #1

    [CLOSED] Possible bug: Viewstate doesn't persist

    Hi, I have a
    problem with following code. When the page is load ViewState["PageID"]
    is loaded and persists during all server trips.
    ViewState["PageContentID"] instead, is loaded in the method
    RowSelected, but doesn't persist.

    RowSelected is not decorated
    as [AjaxMethod] neither is static, so ViewState should be visible and
    working. So where is the problem?

    Here is the code

    Markup
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
            
            <ext:Store ID="DataStore1" runat="server">
                <Reader>
                    <ext:JsonReader ReaderID="IDContent">
                        <Fields>
                            <ext:RecordField Name="Title" />
                            <ext:RecordField Name="SubTitle" />
                            <ext:RecordField Name="ContentText" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            <ext:ViewPort ID="ViewPort1" runat="server">
                <Body>                
                    <ext:BorderLayout ID="BorderLayout1" runat="server">
                        <Center>
                            <ext:GridPanel ID="grdContents" runat="server"
                                StoreID="DataStore1"
                                Frame="false"    
                                Height="400"        
                                Title="Page Contents"                                        
                                >
                                <ColumnModel>
                                    <Columns>                    
                                        <ext:Column DataIndex="Title" Header="Title" Width="165"/>
                                        <ext:Column DataIndex="SubTitle" Header="Subtitle" Width="165"/>
                                        <ext:Column DataIndex="ContentText" Header="Content Text" Width="700"/>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel runat="server" SingleSelect="true">
                                        <AjaxEvents>
                                            <RowSelect OnEvent="RowSelected" Buffer="250">
                                                <EventMask Target="CustomTarget" CustomTarget="#{pnlDetail}"/>
                                                <ExtraParams>
                                                    <ext:Parameter Name="IDContent" Value="this.getSelected().id" Mode="Raw" />
                                                </ExtraParams>
                                            </RowSelect>
                                        </AjaxEvents>
                                    </ext:RowSelectionModel>
                                </SelectionModel>
                            </ext:GridPanel>                    
                        </Center>
                        <South Collapsible="true" >
                            <ext:Panel ID="pnlDetail" runat="server" BodyStyle="padding:5px 5px 0;" Frame="true" Height="300" Title="Edit Content">                            
                                <Body>
                                    <ext:ColumnLayout runat="server">
                                        <ext:LayoutColumn ColumnWidth=".57">
                                            <ext:Panel runat="server" Border="false" Header="false">
                                                <Body>
                                                    <ext:FormLayout ID="FormLayout2" runat="server" LabelAlign="Top">
                                                        <ext:Anchor Horizontal="95%">
                                                            <ext:HtmlEditor ID="htmlEditor" runat="server" Height="200" FieldLabel="Paragrafo" EnableSourceEdit="false"></ext:HtmlEditor>
                                                        </ext:Anchor>
                                                    </ext:FormLayout>
                                                </Body>
                                            </ext:Panel>
                                        </ext:LayoutColumn>
                                        <ext:LayoutColumn ColumnWidth=".43">                                          
                                            <ext:Panel ID="Panel2" runat="server" Border="false" Header="false">
                                                <Body>
                                                    <ext:FormLayout ID="FormLayout3" runat="server" LabelAlign="Top">
                                                        <ext:Anchor Horizontal="95%">
                                                            <ext:TextField ID="txtData" runat="server" FieldLabel="Data"></ext:TextField>
                                                        </ext:Anchor>
                                                    </ext:FormLayout>
                                                </Body>
                                            </ext:Panel>
                                        </ext:LayoutColumn>
                                    </ext:ColumnLayout>
                                </Body>
                                <Buttons>
                                    <ext:Button ID="btnContentSave" runat="server" Text="Salva" Icon="Disk" >                                    
                                        <AjaxEvents><Click OnEvent="btnContentSave_Click" /></AjaxEvents>
                                    </ext:Button>
                                    <ext:Button ID="btnContentCancel" runat="server" Text="Annulla" Icon="Decline" >
                                        <AjaxEvents><Click OnEvent="btnContentCancel_Click" /></AjaxEvents>                                                                        
                                    </ext:Button>
                                </Buttons>
                            </ext:Panel>                        
                        </South>
                    </ext:BorderLayout>
                </Body>
            </ext:ViewPort>
    Codebehind
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    
    using Coolite.Ext.Web;
    
    public partial class CMSEdit : System.Web.UI.Page
    {
        #region Properties
        public string PageID
        {
            set { ViewState["PageID"] = value; }
            get { 
        }
    
        public string PageContentID
        {
            set { ViewState["PageContentID"] = value; }
            get { return ViewState["PageContentID"] as string ?? string.Empty; }
        }
        #endregion
    
        #region Page_Load
        protected void Page_Load( object sender, EventArgs e )
        {
            if ( !Page.IsPostBack )
            {
                if ( Request["id"] != null &amp;&amp; Request["id"].Length > 0 )
                {
                    PageID = Request["id"];
    
                    GridDataBind();
                }
            }
        }
        #endregion
    
        #region Methods
        private void GridDataBind()
        {
            DataStore1.DataSource
                = new CContents( PageID ).GetCurrentDataTable;
            DataStore1.DataBind();
        }
    
        private void ResetSouthPanel()
        {
            PageContentID =
                htmlEditor.Text = String.Empty;
        }
        #endregion
    
        #region Events
        protected void btnContentCancel_Click( object sender, Coolite.Ext.Web.AjaxEventArgs e )
        {
            ResetSouthPanel();
        }
    
        protected void btnContentSave_Click( object sender, Coolite.Ext.Web.AjaxEventArgs e )
        {
            if ( !PageContentID.Equals( String.Empty ) )
            {
                // PageContentID is empty
                CContent content = new CContent( PageContentID );
                //....  some logic....
            }
        }
    
        protected void RowSelected( object sender, AjaxEventArgs e )
        {
            PageContentID = int.Parse( e.ExtraParams["IDContent"] ).ToString();
            // PageContentID is regulary set
        }
        #endregion
    }
    regards,
    Stefano
  2. #2

    RE: [CLOSED] Possible bug: Viewstate doesn't persist

    Hi,

    By default *AjaxEvents don't send ViewState to the client (for save traffic). Therefore if you change ViewState diring AjaxEvent you will not see it during other ajax event.


    You can set ViewStateMode="Include" for particular AjaxEvent or for all request in ScripManager (AjaxViewStateMode="Include")




  3. #3

    RE: [CLOSED] Possible bug: Viewstate doesn't persist


    Ok thank you Vlad for your prompt answer.
    Sorry but I'm busy: I gotta go to study Coolite APIs :)

    Regards, Stefano

Similar Threads

  1. Persist selection with pagination
    By testix in forum 1.x Help
    Replies: 6
    Last Post: May 21, 2014, 12:35 PM
  2. Replies: 0
    Last Post: Mar 19, 2012, 3:08 PM
  3. [CLOSED] How to persist Ext.Net controls in VS2010 toolbox?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 02, 2012, 12:42 PM
  4. Replies: 1
    Last Post: Jun 21, 2010, 3:42 PM
  5. [CLOSED] Persist selection over pagination
    By methode in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Nov 30, 2008, 11:38 AM

Posting Permissions