[CLOSED] Store refresh issue

  1. #1

    [CLOSED] Store refresh issue

    Hi

    I have two pages which are used to insert values trough a gridpanel. One works perfectely the second one shows the following error :

    Click image for larger version. 

Name:	err.png 
Views:	231 
Size:	46.4 KB 
ID:	4708

    It's shown on inserting and on deleting.

    Here is my code :

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConvocationPeriods.aspx.cs" Inherits="Web_ConvocationPeriods" %>
    
    <!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 runat="server">
    <ext:XScript ID="XScript1" runat="server">
            <script type="text/javascript">
                var addNewConvocationPeriod = function () {
                    var grid = #{ConvocationPeriondGridPanel};
                    var store = grid.getStore();
                    grid.editingPlugin.cancelEdit();
                    
    
                    store.insert(0, {
                        SEASONID: #{ddlSeasons}.getValue(),
                        STARTDATE: new Date(),
                        ENDDATE: new Date(),
                        CALENDARDEADLINE: new Date(),
                        CONVOCATIONDEADLINE: new Date()
                    });
    
                    grid.editingPlugin.startEdit(0, 0);
    
                }
                
        </script>
        </ext:XScript>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
    
            <asp:ObjectDataSource ID="ConvPeriodDataSource" runat="server" SelectMethod="ConvocationPeriodSelectBySeason" 
                TypeName="Sigmasport.Code.BusinessLayer.SigmaSportConvocationPeriod" 
                onselecting="ConvPeriodDataSource_Selecting"
                >
                <SelectParameters>
                    <asp:Parameter Name="SEASONID" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
    
            <asp:ObjectDataSource ID="SeasonsDataSource" runat="server" 
            SelectMethod="SeasonSelect" 
            TypeName="Sigmasport.Code.BusinessLayer.SigmaSportSeason" 
            >            
            </asp:ObjectDataSource>    
    
            <ext:Store runat="server" ID="SeasonsStoreID"
             DataSourceID="SeasonsDataSource"                  
             >
                <Model>
                    <ext:Model runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" Type="Int" />
                            <ext:ModelField Name="COMMENT" Type="String" />                
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>                  
            <ext:Store 
             ID="ConvocationPeriodStoreID" 
             runat="server"                 
             DataSourceID="ConvPeriodDataSource"
             onbeforestorechanged="ConvocationPeriodStoreID_BeforeStoreChanged" 
             onreaddata="ConvocationPeriodStoreID_ReadData"
             >
                <Model>                                    
                    <ext:Model runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" Type="Int" />
                            <ext:ModelField Name="SEASONID" Type="Int" />
                            <ext:ModelField Name="STARTDATE" Type="Date" />
                            <ext:ModelField Name="ENDDATE" Type="Date" />
                            <ext:ModelField Name="CALENDARDEADLINE" Type="Date" />
                            <ext:ModelField Name="CONVOCATIONDEADLINE" Type="Date" />
                        </Fields>                    
                    </ext:Model>                
                </Model>           
            </ext:Store>
            <ext:Viewport ID="Viewport1" runat="server" Layout="border" Padding="5">
                <Items>
                    <ext:GridPanel ID="ConvocationPeriondGridPanel" 
                    runat="server"                 
                    StoreID="ConvocationPeriodStoreID" 
                    Frame="true"
                    Padding="5"                
                    Title="<%$ Resources:Resource,ConvocationPeriod %>"                     
                    Icon="ApplicationViewColumns" 
                    Region="Center"                              
                    >
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:Column runat="server" Text="<%$ Resources:Resource,ID %>" DataIndex="ID" Hidden="true" />
                                <ext:DateColumn runat="server" Text="<%$ Resources:Resource,StartDate %>" DataIndex="STARTDATE" Format="dd MMM yyyy" Flex="1">
                                    <Editor>
                                        <ext:DateField ID="DFstartdate" runat="server" DataIndex="STARTDATE" EndDateField="DFenddate" Vtype="daterange" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
                                    </Editor>
                                </ext:DateColumn>                            
                                <ext:DateColumn runat="server" Text="<%$ Resources:Resource,EndDate %>" DataIndex="ENDDATE" Format="dd MMM yyyy" Flex="1">
                                    <Editor>
                                        <ext:DateField ID="DFenddate" runat="server" DataIndex="ENDDATE" StartDateField="DFstartdate" Vtype="daterange" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
                                    </Editor>
                                </ext:DateColumn> 
                                <ext:DateColumn runat="server" Text="<%$ Resources:Resource,CalendarDeadLine %>" DataIndex="CALENDARDEADLINE" Format="dd MMM yyyy" Flex="1">
                                    <Editor>
                                        <ext:DateField runat="server" DataIndex="CALENDARDEADLINE" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
                                    </Editor>
                                </ext:DateColumn> 
                                <ext:DateColumn runat="server" Text="<%$ Resources:Resource,ConvocationDeadLine %>" DataIndex="CONVOCATIONDEADLINE" Format="dd MMM yyyy" Flex="1">
                                    <Editor>
                                        <ext:DateField runat="server" DataIndex="CONVOCATIONDEADLINE" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
                                    </Editor>                            
                                </ext:DateColumn> 
                            </Columns>
                        </ColumnModel>
                        <Plugins>
                            <ext:RowEditing ID="RowEditor1" runat="server" SaveBtnText="<%$ Resources:Resource,Save %>" CancelBtnText="<%$ Resources:Resource,Cancel %>" >                            
                                <Listeners>
                                    <Edit Handler="#{ConvocationPeriodStoreID}.sync();" />
                                    <CancelEdit Handler="#{ConvocationPeriodStoreID}.reload();" />
                                </Listeners>
                            </ext:RowEditing>                          
                        </Plugins>
                        <SelectionModel>
                            <ext:RowSelectionModel runat="server" ID="RowSelectModel1" SingleSelect="true"/>
                        </SelectionModel>
                        <TopBar>
                            <ext:Toolbar runat="server" Padding="5">
                                <Items>
                                    <ext:ComboBox runat="server" ID="ddlSeasons"
                                    StoreID="SeasonsStoreID"  AutoWidth="true"
                                    Width="230"
                                    FieldLabel="<%$ Resources:Resource,Season %>"
                                    DisplayField="COMMENT" ValueField="ID">     
                                        <SelectedItems>
                                            <ext:ListItem Index="-1" />
                                        </SelectedItems>                           
                                        <Listeners>                                    
                                            <Select Handler="#{ConvocationPeriodStoreID}.reload()" />
                                        </Listeners>
                                    </ext:ComboBox>
                                    <ext:ToolbarSeparator runat="server" />
                                    <ext:Button ID="btnNew" runat="server" Icon="Add" Text="<%$ Resources:Resource,AddNew %>">
                                        <Listeners>
                                            <Click Fn="addNewConvocationPeriod" />
                                        </Listeners>
                                    </ext:Button>                                                               
                                    <ext:ToolbarSeparator runat="server" />
                                    <ext:Button ID="btnDelete" runat="server" Icon="Delete" Text="<%$ Resources:Resource,Delete %>">
                                        <Listeners>
                                            <Click Handler="#{ConvocationPeriondGridPanel}.deleteSelected();
                                                               #{ConvocationPeriodStoreID}.sync(); " />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator runat="server" />
                                    <ext:FileUploadField runat="server" ID="btnUpload" Icon="TableSave" ButtonOnly="true" ButtonText="<%$ Resources:Resource, ImportFromFile %>" Enabled="false"></ext:FileUploadField>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                    </ext:GridPanel>
                </Items>
            </ext:Viewport>       
        </div>
        </form>
    </body>
    </html>
    using System;   
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Sigmasport.Code.Shared;
    using Sigmasport.Code.BusinessLayer;
    using Ext.Net;
    using Resources;
    
    public partial class Web_ConvocationPeriods : SigmaSportPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
    
            }
        }
    
        protected void ConvocationPeriodStoreID_BeforeStoreChanged(object sender, BeforeStoreChangedEventArgs e)
        {
            try
            {
                List<Dictionary<string, object>> record = e.DataHandler.ObjectData<Dictionary<string, object>>();
    
                foreach (Dictionary<string, object> r in record)
                {
                    if (e.Action == StoreAction.Create)
                    {
                        ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodInsert");
                        ShowNotification(Resource.M_Notif_ItemCreated);
                    }
                    if (e.Action == StoreAction.Update)
                    {
                        ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodUpdate");
                        ShowNotification(Resource.M_Notif_ItemUpdated);
                    }
                    if (e.Action == StoreAction.Destroy)
                    {
                        ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodDelete");
                        ShowNotification(Resource.M_Notif_ItemDeleted);
                    }
    
                    e.ResponseRecords.Add(r);
                }
    
            }
            catch (Exception ex)
            {
                ExceptionBox(ex.InnerException.Message);
            }
            
            ConvocationPeriodStoreID.Reload();
            e.Cancel = true;
        
        }
    
    
        protected void ConvocationPeriodStoreID_ReadData(object sender, StoreReadDataEventArgs e)
        {
            ConvocationPeriodStoreID.DataBind();
        }
        protected void ConvPeriodDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["SEASONID"] = ddlSeasons.SelectedItem.Value;
        }
    }
    The ConvocationPeriodStoreID_ReadData function is not called when inserting. When deleting, it's called but I still get the error box. All DB operations are correctly proceeded. It seems to be a refresh issue.

    The second page has the same structure, same parameters are set and works perfectly.
    Last edited by Daniil; Sep 03, 2012 at 5:14 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please clarify why do you need this?
    ConvocationPeriodStoreID.Reload();
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Please clarify why do you need this?
    ConvocationPeriodStoreID.Reload();

    I would like to get the inserted record ID which is given by the Database.
  4. #4
    Hi Daniil,

    I found the issue,

    I removed the FileUploadField and it works...

    Thank you for your Help.
  5. #5
    Quote Originally Posted by bossun View Post
    I would like to get the inserted record ID which is given by the Database.
    I don't think you should reload the Store.

    All record values including ids must be returned from a BeforeStoreChanged handler. It is required.

    Lets consider this example.
    https://examples2.ext.net/#/GridPane...reCustomLogic/

    When a user inserts a record and click the Save button, the new record values are submitted to the server and executing the Store1_BeforeChange handler.

    After this code:
    db.Suppliers.InsertOnSubmit(supplier);
    ...
    db.SubmitChanges();
    All inserted records get new ids from a database.

    And these ids and all rest values go to a response here:
    foreach (Supplier supplier in data) {
         e.ResponseRecords.Add(supplier); 
    }
    So, no need to reload the Store.
    Last edited by Daniil; Sep 03, 2012 at 5:14 PM.

Similar Threads

  1. Replies: 1
    Last Post: Oct 26, 2012, 4:49 AM
  2. Replies: 2
    Last Post: Jun 03, 2012, 4:18 PM
  3. Store OnLoad called on every postback
    By wexman in forum 1.x Help
    Replies: 1
    Last Post: Nov 17, 2011, 11:53 AM
  4. [CLOSED] Tasks stop running after store.save() is called
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Oct 11, 2011, 9:06 AM
  5. [CLOSED] Store.reload() not being called in user control
    By IT1333 in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jun 14, 2011, 9:02 PM

Tags for this Thread

Posting Permissions