Oct 01, 2008, 6:43 PM
[CLOSED] ComboBox and HttpProxy
Hello,
If you could run the following example:
Example.aspx:
1. Load page
2. Select "Canada" from first ComboBox
3. Select "Ontario" from second ComboBox
4. Select "Toronto" from forth ComboBox
5. Hit submit
Notice it loaded Canada, and Ontario. How can I make it reload the Toronto?
Need help as soon as possible! :)
Cheers,
Timothy
If you could run the following example:
Example.aspx:
<%@ 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">
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" EnablePartialRendering="True" />
<ext:ScriptManager runat="server" StateProvider="PostBack" />
<ext:ComboBox ID="drpCountry"
runat="server"
Width="255">
<Items>
<ext:ListItem Text="Canada" Value="1" />
<ext:ListItem Text="United Kingdom" Value="2" />
<ext:ListItem Text="United States" Value="3" />
</Items>
<Listeners>
<Select Handler="#{Provinces}.reload();" />
</Listeners>
</ext:ComboBox>
<ext:Store ID="Provinces"
runat="server"
AutoLoad="True">
<Proxy>
<ext:HttpProxy Url="Example-Province.ashx" />
</Proxy>
<Reader>
<ext:JsonReader Root="Province">
<Fields>
<ext:RecordField Name="Text" />
<ext:RecordField Name="Value" DefaultValue="" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
<ext:Parameter Name="CountryId" Value="#{drpCountry}.getValue()" Mode="Raw" />
</BaseParams>
<SortInfo Field="Text" Direction="ASC" />
</ext:Store>
<ExtJS:ComboBox ID="drpProvince"
runat="server"
StoreID="Provinces"
DisplayField="Text"
Editable="True"
EmptyText="----"
ForceSelection="True"
Mode="Local"
Selectonfocus="True"
TriggerAction="All"
TypeAhead="True"
ValueField="Value"
Width="255">
<Listeners>
<Select Handler="#{Cities}.reload();" />
</Listeners>
</ExtJS:ComboBox>
<ext:Store ID="Cities"
runat="server"
AutoLoad="True">
<Proxy>
<ext:HttpProxy Url="Example-City.ashx" />
</Proxy>
<Reader>
<ext:JsonReader Root="City">
<Fields>
<ext:RecordField Name="Text" />
<ext:RecordField Name="Value" DefaultValue="" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
<ext:Parameter Name="ProvinceId" Value="#{drpProvince}.getValue()" Mode="Raw" />
</BaseParams>
<SortInfo Field="Text" Direction="ASC" />
</ext:Store>
<ExtJS:ComboBox ID="drpCity"
runat="server"
StoreID="Cities"
DisplayField="Text"
Editable="True"
EmptyText="----"
ForceSelection="True"
Mode="Local"
Selectonfocus="True"
TriggerAction="All"
TypeAhead="True"
ValueField="Value"
Width="255" />
<ext:Button ID="btnSubmit" runat="server" AutoPostBack="True" onclick="btnSubmit_Click" Text="Submit" />
</form>
</body>
</html>
Example-Province.ashx:<%@ WebHandler Language="C#" Class="Example_Handler" %>
using System;
using System.Collections.Generic;
using System.Web;
using Coolite.Ext.Web;
public class Example_Handler : IHttpHandler
{
public void ProcessRequest (HttpContext Context)
{
if (!String.IsNullOrEmpty(Context.Request["CountryId"]))
{
IList<Dictionary<string, string>> result = new List<Dictionary<string, string>>();
Dictionary<string, string> item1 = new Dictionary<string, string>();
item1.Add("Text", "Ontario");
item1.Add("Value", "ON");
Dictionary<string, string> item2 = new Dictionary<string, string>();
item2.Add("Text", "Quebec");
item2.Add("Value", "QC");
result.Add(item1);
result.Add(item2);
Context.Response.ContentType = "text/json";
Context.Response.Write(String.Format("{{ 'Province' : {0} }}", JSON.Serialize(result)));
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Example-City.ashx:<%@ WebHandler Language="C#" Class="Example_Handler" %>
using System;
using System.Collections.Generic;
using System.Web;
using Coolite.Ext.Web;
public class Example_Handler : IHttpHandler
{
public void ProcessRequest (HttpContext Context)
{
if (!String.IsNullOrEmpty(Context.Request["ProvinceId"]))
{
IList<Dictionary<string, string>> result = new List<Dictionary<string, string>>();
Dictionary<string, string> item1 = new Dictionary<string, string>();
item1.Add("Text", "Toronto");
item1.Add("Value", "TO");
Dictionary<string, string> item2 = new Dictionary<string, string>();
item2.Add("Text", "Ottawa");
item2.Add("Value", "OT");
result.Add(item1);
result.Add(item2);
Context.Response.ContentType = "text/json";
Context.Response.Write(String.Format("{{ 'City' : {0} }}", JSON.Serialize(result)));
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Replication steps:1. Load page
2. Select "Canada" from first ComboBox
3. Select "Ontario" from second ComboBox
4. Select "Toronto" from forth ComboBox
5. Hit submit
Notice it loaded Canada, and Ontario. How can I make it reload the Toronto?
Need help as soon as possible! :)
Cheers,
Timothy