The foreground uses the Ajax direct call backstage method, the old person posts the question, does not have the example
Casmenu.aspx page:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "CasMenu.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>porschev--foreground JS (Jquery) calls the backend method cascading menu </title>
<script src= "Js/jquery-1.3.2-vsdoc.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
$ ("#selPro"). Change (function () {//Province Drop-down Menu Change event
var params = ' {str: ' + $ (this). Val () + ' "} '; Parameter name here to be aware of the same as the background method parameter names
$.ajax ({
Type: "POST",//Submission method
URL: "Casmenu.aspx/showcity",//Submitted page/method name
Data:params,//parameters (if no parameters: null)
DataType: "Text",//Type
ContentType: "Application/json; Charset=utf-8 ",
Beforesend:function (XMLHttpRequest) {
$ (' #tipsDiv '). Text ("Querying ...");
},
Success:function (msg) {
$ (' #tipsDiv '). Text ("Query successful!");
$ ("#selCity option"). each (function () {
$ (this). Remove (); Remove an existing Item
});
$ ("<option value= ' 0 ' >=== please select ===</option>"). Appendto ("#selCity"); Add a Default item
$ (eval ("+ msg +")). D). Appendto ("#selCity"); Add the returned item to the Drop-down menu
},
Error:function (XHR, MSG, e) {
Alert ("Error");
}
});
});
});
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
porschev--foreground JS (Jquery) invokes the Backend method Cascade menu <br/>
<br/>
<select id= "Selpro" name= "Selpro" >
<%=strpro%>
</select> Province (municipality)
<select id= "selcity" name= "selcity" >
<option value= "0" >=== Please select ===</option>
</select> (city)
</div>
<div id= "Tipsdiv" >
</div>
</form>
</body>
CasMenu.aspx.cs
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using Casmenumodels;
Using CASMENUBLL;
Using System.Text;
public partial class _default:system.web.ui.page
{
public static string Strpro = String. Empty; Province dropdown
public static string strcity = String. Empty; City drop down items
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
}
Showpro ();
}
#region # #省份下拉列表框
<summary>
Province Drop-down list box
</summary>
<returns></returns>
public string Showpro ()
{
StringBuilder str = new StringBuilder (); Get all the provinces set up
list<casmenumodels.province> list = new Casmenubll.provincemanager (). Getallprovince (); Add an initial item
Str. Append ("<option value=\");
Str. Append ("0");
Str. Append (">");
Str. Append ("= = = Please select = = =");
Str. Append ("</option>");
Recycle additional Provinces dropdown
foreach (Casmenumodels.province p in list)
{
Str. Append ("<option value=\");
Str. Append (P.provinceid);
Str. Append (">");
Str. Append (P.provincename);
Str. Append ("</option>");
}
return Strpro = str. ToString ();
}
#endregion #region # #城市下拉列表框
<summary>
City Drop-down list Box
</summary>
<param name= "str" > Province id</param>
<returns></returns>
[System.Web.Services.WebMethod ()]
public static string showcity (String str)//method is static
{
StringBuilder Strci = new StringBuilder ();
if (str = = "0")//is the initial item
{
Strci.append ("<option value=\");
Strci.append ("Please choose");
Strci.append (">");
Strci.append ("Please choose");
Strci.append ("</option>");
}
Else
{
list<casmenumodels.city> list = new Casmenubll.citymanager (). Getallbyproid (Convert.ToInt32 (str)); Get the city collection according to the province ID
foreach (city C in list)
{
Strci.append ("<option value=\");
Strci.append (C.cityid);
Strci.append (">");
Strci.append (C.cityname);
Strci.append ("</option>");
}
}
return strcity = Strci.tostring ();
}
#endregion
}
I have a note of where to look,
Of course, the front desk into the background method is far more than this one, for example, and Ajaxpro also very easy to use
SOURCE download