[CLOSED] Problem making ComboBox Search work

  1. #1

    [CLOSED] Problem making ComboBox Search work

    I've tried to do something very similar to the ComboBox search example in the forums. I know that the handler is being called, and I know it's creating the correct data, however the data is not displayed. The screen flashes, but that's it.

    I've attached a trivial example with my simple businessobject that demonstrates my problem.

    Thanks for all the help.
  2. #2

    RE: [CLOSED] Problem making ComboBox Search work

    Hi Peter,

    There were a few configuration issues in the .aspx. I added your sample to the sandbox and made the required changes. The full .aspx file below.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            ObjectDataSource1.SelectParameters["start"].DefaultValue = e.Start.ToString();
            ObjectDataSource1.SelectParameters["limit"].DefaultValue = e.Limit.ToString();
            ObjectDataSource1.SelectParameters["sort"].DefaultValue = e.Sort;
            ObjectDataSource1.SelectParameters["dir"].DefaultValue = e.Dir.ToString();
    
            Store1.DataBind();
        }
    
        protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            (this.Store1.Proxy[0] as DataSourceProxy).TotalCount = (int)e.OutputParameters["count"];
        }
    </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 runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <asp:ObjectDataSource 
                ID="ObjectDataSource1" 
                runat="server"  
                SelectMethod="BOPaging" 
                TypeName="BO.BusinessObject">
                <SelectParameters>
                    <asp:Parameter Name="start" Type="Int32" />
                    <asp:Parameter Name="limit" Type="Int32" />
                    <asp:Parameter Name="sort" Type="String" />
                    <asp:Parameter Name="dir" Type="String" />
                    <asp:Parameter Name="filter" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
            
             <ext:Store 
                ID="Store1" 
                runat="server" 
                AutoLoad="false" 
                RemoteSort="true" 
                DataSourceID="ObjectDataSource1"
                OnRefreshData="Store1_RefreshData">
                <Proxy>
                    <ext:HttpProxy Method="POST" Url="Handler1.ashx" />
                </Proxy>
                <Reader>
                    <ext:JsonReader TotalProperty="totalCount" Root="records" ReaderID="Id">
                        <Fields>
                            <ext:RecordField Name="Id" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Email" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:ComboBox 
                ID="ComboBox1"
                runat="server" 
                StoreID="Store1"
                DisplayField="Name" 
                ValueField="Id"
                TypeAhead="false"
                LoadingText="Searching..." 
                Width="350"
                PageSize="10"
                ItemSelector="div.search-item"        
                MinChars="1">
                <Template ID="Template1" runat="server">
                   <tpl for=".">
                      <div class="search-item">
                         <h3>{Name}</h3>
                         {Email}
                      
    
                   </tpl>
                </Template>
            </ext:ComboBox>  
        </form>
    </body>
    </html>
    One other thing I also noticed is that the 'totalCount' property is returning the wrong value (-1). I'm assuming that number is coming from your BusinessObject somewhere.

    The sample was added to \trunk\Coolite.Sandbox\Temp\Form\ComboBox\Search\

    Hope this helps.

    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] Problem making ComboBox Search work

    Thanks, I'll fix up my object. I need to look more at your Paging .net class. Seems like you guys have some clever stuff in there.
  4. #4

    RE: [CLOSED] Problem making ComboBox Search work

    Two questions:

    1. when I comment out all the lines of code in the events

     protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            ObjectDataSource1.SelectParameters["start"].DefaultValue = e.Start.ToString();
            ObjectDataSource1.SelectParameters["limit"].DefaultValue = e.Limit.ToString();
            ObjectDataSource1.SelectParameters["sort"].DefaultValue = e.Sort;
            ObjectDataSource1.SelectParameters["dir"].DefaultValue = e.Dir.ToString();
    
            Store1.DataBind();
        }
    
        protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            (this.Store1.Proxy[0] as DataSourceProxy).TotalCount = (int)e.OutputParameters["count"];
        }
    Everything still works. I'm having trouble understanding what causes the query string to be passed back to the server side. Can you explain that?

    Also, What actually triggers the post back when I type a character in the textbox?

    Thanks
  5. #5

    RE: [CLOSED] Problem making ComboBox Search work

    Hi Peter,

    1. when I comment out all the lines of code in the events
    Ya, good point. When I was testing/modifying your code sample I didn't pay attention to that code. Sorry. It's not actually required to run the sample and once the HttpProxy is configured, all the ObjectDataStore stuff would be totally ignored.

    With this code sample, the ComboBox runs a query against the Store on the "keyup" event. Once the MinChars count has been reached, every "keyup" event triggers the ComboBox .doQuery function to be fired.

    From that point the Store takes over. The Store is then making an HTTP request to the .Url specified in the HttpProxy.

    You can inspect the query before it's sent to the Store by tapping into the <BeforeQuery> Listener (or AjaxEvent). The following sample demonstrates handling the BeforeQuery Listener and alerting the "query string". The query is then canceled by returning "false" from the Handler.

    Example

    <Listeners>
        <BeforeQuery Handler="Ext.Msg.alert('Query', queryEvent.query);return false;" />
    </Listeners>


    Several params are passed to the .Url. If using FireBug (or Fiddler) you can watch the request being made to the HttpProxy/Url. Three params are sent in the POST request, "query", "limit", and "start".

    query j // the string to query
    limit 10 // the number of records to return
    start 0 // the record count start number

    In the Handler, those values are pulled out the Request object (context.Request["query"]). In your example, the "query" is ultimately passed to into the LINQ query.

    I hope this helps explain what's going on internally.

    I've revised your original code sample and stripped out any of the unnecessary bits.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!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">
        <title>ComboBox with HttpProxy</title>
    </head>
    <body>
    <p><a href="Default.aspx">Reload</a></p>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store 
                ID="Store1" 
                runat="server" 
                AutoLoad="false" 
                RemoteSort="true">
                <Proxy>
                    <ext:HttpProxy Method="POST" Url="Handler1.ashx" />
                </Proxy>
                <Reader>
                    <ext:JsonReader TotalProperty="totalCount" Root="records" ReaderID="Id">
                        <Fields>
                            <ext:RecordField Name="Id" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Email" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:ComboBox 
                ID="ComboBox1"
                runat="server" 
                StoreID="Store1"
                DisplayField="Name" 
                ValueField="Id"
                TypeAhead="false"
                LoadingText="Searching..." 
                Width="350"
                PageSize="10"
                ItemSelector="div.search-item"        
                MinChars="1">
                <%--<Listeners>
                    <BeforeQuery Handler="Ext.Msg.alert('Query', queryEvent.query);return false;" />
                </Listeners>--%>
                <Template ID="Template1" runat="server">
                   <tpl for=".">
                      <div class="search-item">
                         <h3>{Name}</h3>
                         {Email}
                      
    
                   </tpl>
                </Template>
            </ext:ComboBox>  
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  6. #6

    RE: [CLOSED] Problem making ComboBox Search work

    perfect. Thanks.

Similar Threads

  1. Replies: 18
    Last Post: Jul 20, 2011, 8:59 PM
  2. [CLOSED] Problem making ListView not sortable
    By cmack in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 18, 2011, 8:54 PM
  3. Help!!!ComboBox Custom Search 's Problem~
    By st.leo in forum 1.x Help
    Replies: 2
    Last Post: Nov 24, 2010, 9:20 AM
  4. ComboBox Custom Search 's Problem~
    By st.leo in forum 1.x Help
    Replies: 1
    Last Post: Nov 18, 2010, 2:00 AM
  5. [CLOSED] Problem making visible a label after the page is loaded.
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 11, 2010, 12:31 PM

Posting Permissions