[CLOSED] Load data to store of combobox by proxy

  1. #1

    [CLOSED] Load data to store of combobox by proxy

    Hi,

    sample:

    //control
    public delegate void ListSelectParametersEventHandler(Object sender, EventArgs e);
        public class ComboboxLoadOnExpand :Ext.Net.ComboBox
        {
            private Ext.Net.Store store;
            public event ListSelectParametersEventHandler Selecting;
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                store = new Ext.Net.Store();
                Ext.Net.JsonReader reader = new JsonReader();
                reader.Fields.AddRange(new List<RecordField>{new RecordField("Id",RecordFieldType.Int), new RecordField("Name",RecordFieldType.String)});
                store.SortInfo.Direction = SortDirection.ASC;
                store.SortInfo.Field = "Name";
                store.Reader.Add(reader);
                reader.IDProperty = "Id";
                reader.MessageProperty = "Name";
                Ext.Net.HttpProxy proxy = new Ext.Net.HttpProxy();
                proxy.Url = "~/HandlerProxy.ashx";
                proxy.Method = HttpMethod.POST;
                proxy.Timeout = 10000;
                store.Proxy.Add(proxy);
                store.ID = this.ID + "_Store";
                store.AutoLoad = false;
                store.RefreshData += new Ext.Net.Store.AjaxRefreshDataEventHandler(store_RefreshData);
                this.Store.Add(store);
                this.DisplayField = "Name";
                this.ValueField = "Id";
    
            }
            
            protected void store_RefreshData(object sender, StoreRefreshDataEventArgs e)
            {
                Ext.Net.Store store = (Ext.Net.Store) sender;
                
                store.DataBind();
            }
        }
    handler:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Ext.Net;
    
    namespace Ext1._6Test
    {
        [Serializable]
        class MyClass
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public MyClass(int id, string name)
            {
                Id = id;
                Name = name;
            }
        }
        /// <summary>
        /// Summary description for HandlerProxy
        /// </summary>
        public class HandlerProxy : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                List<MyClass> myClasses = new List<MyClass>()
                                              {
                                                  new MyClass(1,"first"),
                                                  new MyClass(2,"second"),
                                                  new MyClass(3,"third")
                                              };
                
                context.Response.Write(JSON.Serialize(myClasses));
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    page:
    <%@ Page Title="" Language="C#" MasterPageFile="~/Page.Master" AutoEventWireup="true" CodeBehind="Start.aspx.cs" Inherits="Ext1._6Test.Start" %>
    <script runat="server">
    protected void myCombo_Selecting(object sender, EventArgs e)
            {
                //here I want to add some parameters and then run handler
            }
    </script>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" %>
    <%@ Register TagPrefix="uc" Namespace="Ext1._6Test.controls" Assembly="Ext1.6Test" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <ext:Container runat="server" Layout="Fit">
            <Items>
                <ext:Button runat="server" Text="btn Start Page"></ext:Button>
                <uc:ComboboxLoadOnExpand ID="myCombo" runat="server" Selecting="myCombo_Selecting"/>
            </Items>
        </ext:Container>
    </asp:Content>
    What I need to do is load data by proxy. I've made that already but I need load some of extra parameters before make this request on handler side.

    I hope requirements are clear enough:) I've make comment in code what I need to do before handler request will go to server.
    How can I do this?

    Regards,
    ViDom
    Last edited by Daniil; Oct 08, 2012 at 8:36 AM. Reason: [CLOSED]
  2. #2
    Hi @ViDom,

    HttpProxy makes a request client side. So, you should add custom parameters client side.

    What about to use Store Parameters collection? Or you can pass parameters calling the JavaScript Store load method.

    If you would provide more details about the requirement, i.e. about the parameters that you need to add on the fly, we could suggest something concrete.

    Also RefreshData handler doesn't make any sense when a Store is configured with the HttpProxy.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ViDom,

    HttpProxy makes a request client side. So, you should add custom parameters client side.

    What about to use Store Parameters collection? Or you can pass parameters calling the JavaScript Store load method.

    If you would provide more details about the requirement, i.e. about the parameters that you need to add on the fly, we could suggest something concrete.

    Also RefreshData handler doesn't make any sense when a Store is configured with the HttpProxy.
    If I write:
    string paramt = JSON.Serialize(requestParams.Parameters);
    store.WriteBaseParams["session_name_combobox_searchparams"] = paramt;
    paramt are serialized ok. But in handler there is no way to read it (always null) in:

    context.Request["session_name_combobox_searchparams"]
    Same with
    store.BaseParams["session_name_combobox_searchparams"] = paramt;
    Any suggestion?
  4. #4
    WriteBaseParams are for save requests.

    BaseParams are for load requests.

    Please clarify where you populate the BaseParams collection?

    Can you use see these parameters in a request?
  5. #5
    Quote Originally Posted by Daniil View Post
    WriteBaseParams are for save requests.

    BaseParams are for load requests.

    Please clarify where you populate the BaseParams collection?

    Can you use see these parameters in a request?
    I populate BaseParams in OnInit event of my custom control.

    Sometimes I can see them but always there are null in context (even when in debug I can see there are some of my params);

    Edit:
    Here is value of context.Request.Form:
    session_name_combobox=ContractorP_Id_Store&session_name_combobox_searchparams=%7b%22DsTypeName%22%3a%22Contractor%22%2c%22DsMethod%22%3a%22GetList%22%2c%22DsParameters%22%3a%7b%7d%2c%22DsParametersList%22%3a%5b%5d%2c%22ClientInitialFilter%22%3anull%2c%22ClientFiltersList%22%3anull%2c%22ClientJoinType%22%3a%22And%22%2c%22ClientSort%22%3anull%2c%22PageIndex%22%3a0%2c%22PageSize%22%3a0%2c%22PrintData%22%3a%7b%22VisibleFields%22%3anull%2c%22XsltTemplate%22%3anull%2c%22Xml%22%3anull%2c%22Data%22%3anull%7d%7d&session_name_combobox_datatypename=Contractor&query=
    when I check:
    !string.IsNullOrEmpty(context.Request["session_name_combobox_searchparams"])
    it's always false.
  6. #6
    Please provide a sample to reproduce. We will do our best to investigate.
  7. #7
    Quote Originally Posted by Daniil View Post
    Please provide a sample to reproduce. We will do our best to investigate.
    I've made simply mistake and wrote different key in handler ;/

    Thread can be closed.

Similar Threads

  1. Replies: 13
    Last Post: Sep 07, 2012, 6:23 PM
  2. [CLOSED] Ext.data.store.load()
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 01, 2010, 10:24 PM
  3. Store data does not load in panel's field.
    By ankit in forum 1.x Help
    Replies: 0
    Last Post: May 25, 2010, 8:44 AM
  4. combobox not load data
    By maxdiable in forum 1.x Help
    Replies: 2
    Last Post: Feb 05, 2010, 12:48 PM
  5. 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

Tags for this Thread

Posting Permissions