[CLOSED] problem with dynamic store on postback

  1. #1

    [CLOSED] problem with dynamic store on postback



    Hi

    I am building page wich creates store and gridpanel dynamically. Everything works when page loads. I have a button on grid which calls grid.reload(); when that happens, i get the following error. Do i need to use reconfigure on AjaxEvent. How I can make sure that my grid reloads on AjaxEvent Thanks - Idriss

    An exception of type 'System.Web.HttpException' occurred in Coolite.Ext.Web.DLL but was not handled in user code</p>
    
    
    Additional information: The control with ID 'store1' not found
    
    this is coming from scriptManager.cs
    aspx page
    </p>
    
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="tblproperties.aspx.cs" Inherits="tblproperties" %></p>
    
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %></p>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></p>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml"></p>
    
    
    <head runat="server" id="Head1"></p>
    
    
    <ext:ScriptContainer ID="ScriptContainer1" runat="server" ></p>
    
    
    <link href='<%= ResolveUrl("~/css/panel.css") %>' rel="stylesheet" type="text/css" /></p>
    
    
    </ext:ScriptContainer></p>
    
    
    <script src="../JavaScript/jquery-1.3.2.min.js" type="text/javascript"></script></p>
    
    
    </head></p>
    
    
    <body></p>
    
    
    <form id="theForm" runat="server"></p>
    
    
    </p>
    
    
    <asp:PlaceHolder runat="server" ID="ph1"></asp:PlaceHolder></p>
    
    
    </p>
    
    
    <ext:ScriptManager ID="ScriptManager1" runat="server"></p>
    
    
    </ext:ScriptManager></p>
    
    
    </p>
    
    
    <asp:HiddenField ID="hfSection" EnableViewState="true" runat="server" /></p>
    
    
    </p>
    
    
    </p>
    
    
    <ext:ViewPort ID="ViewPort1" runat="server"></p>
    
    
    <Body></p>
    
    
    <ext:BorderLayout ID="BorderLayout1" runat="server"></p>
    
    
    <North MarginsSummary="5 5 5 5"></p>
    
    
    <ext:Panel ID="pnlTop" runat="server" Header="false" Frame="true" AutoHeight="true"</p>
    
    
    BodyStyle="padding: 5px;background-color:#ffffff;" ></p>
    
    
    <Body></p>
    
    
    <div ></p>
    
    
    <div style="float: left; width: 49%;"></p>
    
    
    <label class="tdText"></p>
    
    
    <input type="checkbox" id="cbComplete" onclick="changeIcon(this, &#100;ocument.getElementById('hfSection').value)" />Mark</p>
    
    
    this section as complete and accurate</label></p>
    
    
    
    </p>
    
    
    
    </p>
    
    
    <br /></p>
    
    
    <div style="width: 100%;"></p>
    
    
    <!-- BEGIN EXPAND --></p>
    
    
    <wc:wc_Expander runat="server" ID="expand1" MessageHeader="Additional Information" </p>
    
    
    MessageBody="Please review the information below. To view additional information on a specific</p>
    
    
    item or to change any of the information displayed, click on Change. For any numerical</p>
    
    
    fields, enter only whole numbers - do not enter dollar signs, decimal points or</p>
    
    
    commas. When finished, click on Save. To add a new item, click on Add New button</p>
    
    
    at the top of the form. To delete an item, click on Remove. Once you are finished</p>
    
    
    reviewing all the information, click the box next to Mark this section as complete</p>
    
    
    and accurate. For additional help, click on the Instructions tab." /></p>
    
    
    <!-- END EXPAND --></p>
    
    
    </p>
    
    
    
    </p>
    
    
    </Body></p>
    
    
    </ext:Panel></p>
    
    
    </North></p>
    
    
    <Center MarginsSummary="0 5 5 5"></p>
    
    
    <ext:Panel ID="pnlBottom" runat="server" Frame="true" Header="false"></p>
    
    
    <Body></p>
    
    
    </Body></p>
    
    
    </ext:Panel></p>
    
    
    </Center></p>
    
    
    </ext:BorderLayout></p>
    
    
    </Body></p>
    
    
    </ext:ViewPort></p>
    
    
    </p>
    
    
    </p>
    
    
    </p>
    
    
    </p>
    
    
    </form></p>
    
    
    </body></p>
    
    
    </html>
    code behind simplified
    </p>
    
    
    using System;</p>
    
    
    using System.Collections.Generic;</p>
    
    
    using System.Web;</p>
    
    
    using System.Web.UI;</p>
    
    
    using System.Web.UI.WebControls;</p>
    
    
    using log4net;</p>
    
    
    using Resources;</p>
    
    
    using System.Linq;</p>
    
    
    using D2D.Extensions;</p>
    
    
    using IFG.Data.NavRisk;</p>
    
    
    using Coolite.Ext.Web;
    
    </p>
    
    
    public partial class tblproperties: IFG.Web.PageBase</p>
    
    
    {</p>
    
    
    public string PolicyID </p>
    
    
    {</p>
    
    
    get</p>
    
    
    {</p>
    
    
    object obj = ViewState["PolicyID"];</p>
    
    
    return (obj == null) ? string.Empty : (string)obj;</p>
    
    
    }</p>
    
    
    set</p>
    
    
    {</p>
    
    
    ViewState["PolicyID"] = value;</p>
    
    
    } </p>
    
    
    }</p>
    
    
    protected void Page_Load(object sender, EventArgs e)</p>
    
    
    { </p>
    
    
    if (!IsPostBack &amp;&amp; !Ext.IsAjaxRequest)</p>
    
    
    {</p>
    
    
    PolicyID = IFG.Data.NavRiskController.GetPolicyID(this.IFG_CurrentMemberID);</p>
    
    
    CreateGrid();</p>
    
    
    } </p>
    
    
    }</p>
    
    
    protected void GridRefresh(object sender, StoreRefreshDataEventArgs e)</p>
    
    
    {</p>
    
    
    CreateGrid();</p>
    
    
    }</p>
    
    
    private void CreateGrid()</p>
    
    
    {</p>
    
    
    </p>
    
    
    Dictionary<string, IFG.WebControls.DataBoundField> listColumns = CreateColumnsCollection<Properties>();</p>
    
    
    HttpContext.Current.Cache["listcolumns"] = listColumns;</p>
    
    
    Store store = new Store { ID = "store1" };</p>
    
    
    this.ph1.Controls.Add(store);</p>
    
    
    </p>
    
    
    store.RefreshData += new Store.AjaxRefreshDataEventHandler(GridRefresh);</p>
    
    
    store.AutoLoad = true;</p>
    
    
    store.Reader.Add(new JsonReader());</p>
    
    
    #region Grid Definition</p>
    
    
    GridPanel grid = new GridPanel</p>
    
    
    {</p>
    
    
    ID = "grid2",</p>
    
    
    AutoScroll = true,</p>
    
    
    //AutoHeight = true,</p>
    
    
    StoreID = store.ID,</p>
    
    
    StripeRows = true,</p>
    
    
    Header = false,</p>
    
    
    AutoWidth = true</p>
    
    
    };</p>
    
    
    grid.LoadMask.ShowMask = true;</p>
    
    
    grid.LoadMask.Msg = "Loading...";</p>
    
    
    FitLayout fit1 = new FitLayout();</p>
    
    
    fit1.Items.Add(grid);</p>
    
    
    </p>
    
    
    pnlBottom.BodyControls.Add(fit1);</p>
    
    
    Coolite.Ext.Web.PagingToolbar pager = new Coolite.Ext.Web.PagingToolbar { PageSize = 20 };</p>
    
    
    grid.BottomBar.Add(pager);</p>
    
    
    Coolite.Ext.Web.Toolbar tb = new Coolite.Ext.Web.Toolbar();</p>
    
    
    Coolite.Ext.Web.ToolbarButton button = new Coolite.Ext.Web.ToolbarButton();</p>
    
    
    button.ID = "btnAdd";</p>
    
    
    button.Text = "Add New";</p>
    
    
    button.Icon = Icon.Add;</p>
    
    
    tb.Items.Add(button);</p>
    
    
    button = new Coolite.Ext.Web.ToolbarButton();</p>
    
    
    button.ID = "btnExport"; </p>
    
    
    button.Text = "Export";</p>
    
    
    button.Icon = Icon.HtmlGo;</p>
    
    
    tb.Items.Add(button);</p>
    
    
    button = new Coolite.Ext.Web.ToolbarButton();</p>
    
    
    button.ID = "btnRefresh";</p>
    
    
    button.Text = "Refresh";</p>
    
    
    button.AutoPostBack = false;</p>
    
    
    button.Icon = Icon.ArrowRefresh;</p>
    
    
    button.Listeners.Click.Handler = "grid2.reload();";</p>
    
    
    tb.Items.Add(button);</p>
    
    
    </p>
    
    
    grid.TopBar.Add(tb);</p>
    
    
    #endregion</p>
    
    
    #region Create Reader for Store</p>
    
    
    ((Coolite.Ext.Web.JsonReader)store.Reader[0]).ReaderID = "reader1";</p>
    
    
    Coolite.Ext.Web.RecordField field = null;</p>
    
    
    field = new Coolite.Ext.Web.RecordField("col1", Coolite.Ext.Web.RecordFieldType.Auto);</p>
    
    
    field = new Coolite.Ext.Web.RecordField("col2", Coolite.Ext.Web.RecordFieldType.Auto);</p>
    
    
    
    #endregion
    </p>
    
    </p>store.Reader[0].Fields.Add(field);
    
    </p>
    
    
    Coolite.Ext.Web.Column _col = new Coolite.Ext.Web.Column</p>
    
    
    {</p>
    
    
    ColumnID = cc.ColumnName,</p>
    
    
    Header = cc.ColumnHeader,</p>
    
    
    DataIndex = cc.ColumnName,</p>
    
    
    Sortable = cc.IsSortable,</p>
    
    
    Width = 100,</p>
    
    
    Hidden = false</p>
    
    
    };</p>
    
    
    
    </p>
    
    </p>grid.ColumnModel.Columns.Add(_col);
    
    </p>
    
    
     </p>
    
    
    }</p>
    
    
    // if we need to add Edit/Delete columns</p>
    
    
    Coolite.Ext.Web.CommandColumn commandColumn = new Coolite.Ext.Web.CommandColumn { ColumnID = "actionButton", Header = "Action", DataIndex = "ActionButton", Sortable = false, Width = 80 };</p>
    
    
    Coolite.Ext.Web.GridCommand deleteColumn = new Coolite.Ext.Web.GridCommand { Icon = Icon.Delete, CommandName = "Delete" };</p>
    
    
    Coolite.Ext.Web.CommandSeparator sepColumn = new CommandSeparator();</p>
    
    
    Coolite.Ext.Web.GridCommand editColumn = new Coolite.Ext.Web.GridCommand { Icon = Icon.NoteEdit, CommandName = "Edit" };</p>
    
    
    commandColumn.Commands.Add(deleteColumn);</p>
    
    
    commandColumn.Commands.Add(sepColumn);</p>
    
    
    commandColumn.Commands.Add(editColumn);</p>
    
    
    grid.ColumnModel.Columns.Add(commandColumn);</p>
    
    
    #endregion</p>
    
    
    col = IFG.Data.RQController.GetProperties(PolicyID);</p>
    
    
    store.DataSource = col;</p>
    
    
    store.DataBind();</p>
    
    
    </p>
    
    
    }</p>
    
    
    </p>
    
    
    </p>
    
    
    </p>
    
    
    }
    </p>
  2. #2

    RE: [CLOSED] problem with dynamic store on postback

    Hi,

    You have to recreate dynamic controls on each request. Therefore move CreateGrid calling outside 'if' statement
  3. #3

    RE: [CLOSED] problem with dynamic store on postback

    thanks vlad
    should have thought of that. please mark as solved.
    idriss
  4. #4

    RE: [CLOSED] problem with dynamic store on postback



    you must be override SaveViewState and LoadViewState method,e.g:
    protected override void LoadViewState(object savedState)
    {
    base.LoadViewState(savedState);


    /*pOpType 0:Insert 1:Modify 2:View*/
    int pOpType = int.Parse((string)Request.Params["pOpType"]);


    //get the sql from viewsate object
    if (ViewState["TextBox_Sql.Text"] != null)
    TextBox_Sql.Text = ViewState["TextBox_Sql.Text"].ToString();
    // recreate dynamic controls
    if (ColumnsAdded)
    {
    CreateTemplateColumn();
    }
    }


    protected override object SaveViewState()
    {
    //Save the sql to ViewSate
    ViewState["TextBox_Sql.Text"] = TextBox_Sql.Text;
    return (base.SaveViewState());
    }
    private bool ColumnsAdded
    {
    get
    {
    object ObjAdd = ViewState["ColumnsAdded"];
    if (ObjAdd == null) return false;
    else return (bool)ObjAdd;
    }
    set
    {
    ViewState["ColumnsAdded"] = value;
    }
    }

Similar Threads

  1. Render dynamic store id in client different when postback
    By Nhím Hổ Báo in forum 1.x Help
    Replies: 1
    Last Post: May 03, 2012, 8:50 PM
  2. [CLOSED] [1.0] Dynamic Controls and Postback
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 25, 2011, 8:08 AM
  3. Dynamic store and grid problem
    By Varlynstroud in forum 1.x Help
    Replies: 2
    Last Post: Aug 19, 2009, 11:03 AM
  4. Dynamic Store/Grid Load on Postback - no data.
    By rthiney in forum 1.x Help
    Replies: 4
    Last Post: Aug 12, 2009, 7:38 AM
  5. TabPanel Dynamic Tab PostBack
    By Timothy in forum Bugs
    Replies: 4
    Last Post: Aug 24, 2008, 2:52 PM

Posting Permissions