First we need a to create simple Ajax xmlHttp object and get Which country is selected by using java script. Pass Country to server side Script/page, select all the states with in that country from Data base and pass it to client side using the same xmlHttp
(System.Web.HttpContext.Current.Response.Write("All States"))
server side page name ajaxState.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="StateTableAdapters" %>
<%@ Import Namespace="System.Data" %>
<%
if (Request.QueryString["Country"] != null)
{
String Country = Request.QueryString["Country"].ToString();
StringBuilder strAllStaters = new StringBuilder();
strddl.Append(" <select id=selState' style='border: 1px solid DarkBlue; width: 150px;'>");
strddl.Append("<option value=\"0\">");
while(Dtr.Read())
strddl.Append(Dtr["Country "].ToString());
}
strddl.Append("</select>");
System.Web.HttpContext.Current.Response.Write(strAllStaters);
> }
%>
<script type="text/javascript">
function ajaxFunction() {
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e) { // Internet Explorer
try {
}
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (document.getElementById('selCountry’).selectedIndex > 0)
Note:I am setting the respose text to innerHTML of a div (selDiv)
document.getElementById("divState").innerHTML = xmlHttp.responseText;