Restore grid state in ext.net not working after reopening the application

  1. #1

    Restore grid state in ext.net not working after reopening the application

    Restore grid state in ext.net not working after reopening the application

    My test -
    1. Hide any one column. e..g 'Fax'
    2. Close the application.
    3. Run the application again by ctrl+F5
    4. the column 'Fax' should have been hidden. But it is showing that column also.
    It works for F5 but does not work it for reopening the appl.
    Please help.


    Here is my code -

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="Button=Ext.Net.Button" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">
        
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(Server.MapPath("States.xml"));
    
            foreach (XmlNode state in xml.SelectNodes("states/state"))
            {
                this.cbStates.Items.Add(new Ext.Net.ListItem(state.Attributes["label"].InnerText, state.Attributes["data"].InnerText));
            }
        }
    
        private bool cancel;
        private string message;
        private string insertedValue;
    
        protected void Store1_BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
        {
            object region = e.NewValues["Region"];
            
            if (region == null || region.ToString() != "Alabama (AL)")
            {
                e.Cancel = true;
                this.cancel = true;
                this.message = "The Region must be 'AL'";
            }
        }
    
        protected void Store1_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
        {
            //The deleted and updated records confirms automatic (depending AffectedRows field)
            //But you can override this in AfterRecordUpdated and AfterRecordDeleted event
            //For insert we should set new id for refresh on client
            //If we don't set new id then old id will be used
            if (e.Confirmation.Confirm && !string.IsNullOrEmpty(insertedValue))
            {
                e.Confirmation.ConfirmRecord(insertedValue);
                insertedValue = "";
            }
        }
    
        protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {
            //use e.AffectedRows for ensure success action. The store read this value and set predefined Confirm depend on e.AffectedRows
            //The Confirm can be granted or denied in OnRecord....ed event
            insertedValue = e.Command.Parameters["@newId"].Value != null
                                ? e.Command.Parameters["@newId"].Value.ToString()
                                : "";
        }
    
        protected void Store1_AfterDirectEvent(object sender, AfterDirectEventArgs e)
        {
            if (e.Response.Success)
            {
                // set to .Success to false if we want to return a failure
                e.Response.Success = !cancel;
                e.Response.Message = message;
                //if (this.cancel)
               // {
                   // GridPanel1.AddScript("alert({0});", JSON.Serialize(this.message));
                //}
            }
        }
    
        protected void Store1_BeforeDirectEvent(object sender, BeforeDirectEventArgs e)
        {
            string emulError = e.Parameters["EmulateError"];
            
            if (emulError == "1")
            {
                throw new Exception("Emulating error");
            }
        }
    
        protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
        {
            this.Store1.DataBind();
        }
    
        protected void InsertColumn(object sender, DirectEventArgs e)
        {
            ((Button)sender).Disabled = true;
    
            DateColumn col = new DateColumn
            {
                Header = "Last Updated",
                Width = 85,
                Sortable = true,
                DataIndex = "lastChange",
                Format = "M/d/yyyy"
            };
    
            this.GridPanel1.InsertColumn(1, col);
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>AJAX GridPanel with Details - Ext.NET Examples</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager runat="server" StateProvider="Cookie"/>
            
            <asp:SqlDataSource 
                ID="SqlDataSource1" 
                runat="server" 
                ConnectionString="<%$ ConnectionStrings:GridAppConnectionString %>"
                DeleteCommand="DELETE FROM Suppliers WHERE (SupplierID = @SupplierID)"
                InsertCommand="INSERT INTO Suppliers 
                                   (CompanyName,
                                    ContactName,
                                    ContactTitle, 
                                    Address, 
                                    City, 
                                    Region, 
                                    PostalCode, 
                                    Country, 
                                    Phone, 
                                    Fax) 
                                VALUES 
                                    (@CompanyName,
                                     @ContactName,
                                     @ContactTitle,
                                     @Address,
                                     @City,
                                     @Region,
                                     @PostalCode,
                                     @Country,
                                     @Phone,
                                     @Fax);                         
                                SELECT @newId = @@Identity;"
                                
                SelectCommand="SELECT 
                                    SupplierID, 
                                    CompanyName, 
                                    ContactName, 
                                    ContactTitle, 
                                    Address, 
                                    City, 
                                    Region, 
                                    PostalCode, 
                                    Country, 
                                    Phone, 
                                    Fax                            
                               FROM Suppliers"
                               
                UpdateCommand="UPDATE Suppliers SET 
                                    CompanyName = @CompanyName, 
                                    ContactName = @ContactName, 
                                    ContactTitle = @ContactTitle, 
                                    Address = @Address, 
                                    City = @City, 
                                    Region = @Region, 
                                    PostalCode = @PostalCode, 
                                    Country = @Country, 
                                    Phone = @Phone, 
                                    Fax = @Fax
                               WHERE (SupplierID = @SupplierID)"
                               
                OnInserted="SqlDataSource1_Inserted">
                
                <DeleteParameters>
                    <asp:Parameter Name="SupplierID" Type="Int32" />
                </DeleteParameters>
                
                <UpdateParameters>
                    <asp:Parameter Name="CompanyName" Type="String" />
                    <asp:Parameter Name="ContactName" Type="String" />
                    <asp:Parameter Name="ContactTitle" Type="String" />
                    <asp:Parameter Name="Address" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="Region" Type="String" />
                    <asp:Parameter Name="PostalCode" Type="String" />
                    <asp:Parameter Name="Country" Type="String" />
                    <asp:Parameter Name="Phone" Type="String" />
                    <asp:Parameter Name="Fax" Type="String" />
                    <asp:Parameter Name="SupplierID" Type="Int32" />
                </UpdateParameters>
                
                <InsertParameters>
                    <asp:Parameter Name="CompanyName" Type="String" />
                    <asp:Parameter Name="ContactName" Type="String" />
                    <asp:Parameter Name="ContactTitle" Type="String" />
                    <asp:Parameter Name="Address" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="Region" Type="String" />
                    <asp:Parameter Name="PostalCode" Type="String" />
                    <asp:Parameter Name="Country" Type="String" />
                    <asp:Parameter Name="Phone" Type="String" />
                    <asp:Parameter Name="Fax" Type="String" />
                    <asp:Parameter Name="newId" />
                </InsertParameters>
            </asp:SqlDataSource>
            
            <ext:Store 
                ID="Store1" 
                runat="server" 
                DataSourceID="SqlDataSource1" 
                ShowWarningOnFailure="false"
                OnAfterDirectEvent="Store1_AfterDirectEvent"
                OnBeforeDirectEvent="Store1_BeforeDirectEvent" 
                UseIdConfirmation="true" 
                OnBeforeRecordInserted="Store1_BeforeRecordInserted"
                OnAfterRecordInserted="Store1_AfterRecordInserted"
                OnRefreshData="Store1_RefershData">
                <Reader>
                    <ext:JsonReader IDProperty="SupplierID">
                        <Fields>
                            <ext:RecordField Name="CompanyName" />
                            <ext:RecordField Name="ContactName" />
                            <ext:RecordField Name="ContactTitle" />
                            <ext:RecordField Name="Address" />
                            <ext:RecordField Name="City" />
                            <ext:RecordField Name="Region" />
                            <ext:RecordField Name="PostalCode" />
                            <ext:RecordField Name="Country" />
                            <ext:RecordField Name="Phone" />
                            <ext:RecordField Name="Fax" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <SortInfo Field="CompanyName" Direction="ASC" />
                <Listeners>
                    <LoadException Handler="Ext.Msg.alert('Suppliers - Load failed', e.message || e);" />
                    <CommitFailed Handler="Ext.Msg.alert('Suppliers - Commit failed', 'Reason: ' + msg);" />
                    <SaveException Handler="Ext.Msg.alert('Suppliers - Save failed', e.message || e);" />
                    <CommitDone Handler="Ext.Msg.alert('Suppliers - Commit', 'The data successfully saved');" />
                </Listeners>      
            </ext:Store>
            
            <ext:Viewport runat="server" Stateful=true>
                <Items>
                    <ext:BorderLayout runat="server">
                        <North MarginsSummary="5 5 5 5">
                            <ext:Panel 
                                runat="server" 
                                Title="Description" 
                                Height="100" 
                                Padding="5"
                                Frame="true" 
                                Icon="Information">
                                <Content>
                                    Example - Ajax update (insert/delete/update) with SqlDataSource.
                                    <br />
                                    For demo purpose when insert action perfoms, the Region must be &quot;AL&quot; otherwise
                                    custom data validation will fail and return error message.
                                </Content>
                            </ext:Panel>
                        </North>
                        <Center MarginsSummary="0 5 0 5">
                            <ext:Panel ID="Panel1" runat="server" Height="300" Header="false" Layout="Fit">
                                <Items>
                                    <ext:GridPanel 
                                        ID="GridPanel1" 
                                        runat="server"  
                                        Title="Suppliers" 
                                        AutoExpandColumn="CompanyName"
                                        StoreID="Store1"
                                        Stateful="True"
                                        Border="false" 
                                        Icon="Lorry">
                                        <ColumnModel runat="server">
                                            <Columns>
                                                <ext:Column 
                                                    ColumnID="CompanyName" 
                                                    DataIndex="CompanyName" 
                                                    Header="Company Name">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column1" DataIndex="ContactName" Header="Contact Name">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column2" DataIndex="ContactTitle" Header="Contact Title">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column3" DataIndex="Address" Header="Address">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column4" DataIndex="City" Header="City">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column5" DataIndex="Region" Header="Region" Width="200">
                                                    <Editor>
                                                        <ext:ComboBox ID="cbStates" runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column6" DataIndex="PostalCode" Header="Postal Code">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column7" DataIndex="Country" Header="Country">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column8" DataIndex="Phone" Header="Phone">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column  ColumnID="Column9" DataIndex="Fax" Header="Fax">
                                                    <Editor>
                                                        <ext:TextField runat="server" />
                                                    </Editor>
                                                </ext:Column>                                            
                                            </Columns>
                                        </ColumnModel>                                    
                                        <SelectionModel>
                                            <ext:RowSelectionModel runat="server" />
                                        </SelectionModel>
                                        <BottomBar>
                                            <ext:PagingToolbar 
                                                runat="server" 
                                                PageSize="10" 
                                                StoreID="Store1" 
                                                DisplayInfo="false" 
                                                />
                                        </BottomBar>
                                        <SaveMask ShowMask="true" />
                                        <LoadMask ShowMask="true" />
                                    </ext:GridPanel>
                                </Items>
                                <Buttons>
                                    <ext:Button ID="btnSave" runat="server"  Text="Save" Icon="Disk">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.save();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnDelete" runat="server"  Text="Delete selected records" Icon="Delete">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.deleteSelected();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnInsert" runat="server"  Text="Insert" Icon="Add">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.insertRecord(0, {});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.startEditing(0, 0);" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnRefresh" runat="server"  Text="Refresh" Icon="ArrowRefresh">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.reload();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnInsertCol" runat="server"  Text="Insert Column" Icon="Add">
                                        <DirectEvents>
                                             <Click OnEvent="InsertColumn" Single="true" />
                                        </DirectEvents>
                                    </ext:Button>
                                    <ext:Button ID="btnEmulError" runat="server"  Text="Refresh with Emulated error" Icon="Exclamation">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.reload({params:{EmulateError: 1}});" />
                                        </Listeners>
                                    </ext:Button>                           
                                </Buttons>
                            </ext:Panel>
                        </Center>             
                    </ext:BorderLayout>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    Please check and let me know why this is not working?
    Last edited by Daniil; Dec 07, 2011 at 7:35 AM. Reason: Please use [CODE] tags
  2. #2
    Pretty much standard browser behaviour. The second post shows you what kind of behaviour you can expect in different browsers.
    http://stackoverflow.com/questions/3...eshes-generate
  3. #3

    This makes sense...will try with IE8 and see how it works...Thanx

    This makes sense...will try with IE8 and see how it works...Thanx

    Quote Originally Posted by hc.dev View Post
    Pretty much standard browser behaviour. The second post shows you what kind of behaviour you can expect in different browsers.
    http://stackoverflow.com/questions/3...eshes-generate

Similar Threads

  1. [CLOSED] Grid State Restore - Hidden Column
    By ecerrillos in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jul 11, 2014, 4:28 PM
  2. Application stops working after some time
    By mercede75 in forum 1.x Help
    Replies: 0
    Last Post: May 18, 2012, 6:47 AM
  3. Replies: 2
    Last Post: Jul 11, 2011, 6:16 PM
  4. Replies: 4
    Last Post: Apr 28, 2011, 2:28 AM
  5. [CLOSED] Restore State?
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 20, 2010, 1:58 PM

Posting Permissions