Ajax Simple Application code
@ WebHandler language= "C #" class= "handler"%>
using System;
Using System.Web;
Using System.Collections.Generic;
Using System.Data;
public class Handler:ihttphandler
{
public void GetPage (HttpContext context)
{
int pagenum = Convert.ToInt32 (context.request["Pagenum"]);
pagenum++;
if (Pagenum <= 3)
{
Dataset1.productdatatable CacheData =
(dataset1.productdatatable) context.cache["CacheKey"];
if (CacheData = null)
{
CacheData = new
Dataset1tableadapters.producttableadapter (). GETDATABYPRICEASC (1, 15);
Context.Cache.Insert ("CacheKey", CacheData, NULL,
System.web.caching.cache.noabsoluteexpiration, Timespan.fromseconds
(80));
}
List<product> news = new list<product> ();
for (int i = (Pagenum * 5)-4; I <= pagenum * 5; i++)
{
Dataset1.productrow row = cachedata[i-1];
string s = Link.toproduct (row.productid.tostring ());
News.add (new Product ()
{
Name = Row.name,
Description = Row.description,
Price = Row.price.tostring (),
thumbnail = Row.thumbnail,
Path = s
});
}
System.web.script.serialization. Web Effects Serializer JSS =
New system.web.script.serialization. Web effects Serializer ();
Context.Response.Write (News) (jss.serialize);
}
Else
{
var data = new
Dataset1tableadapters.producttableadapter (). GETDATABYPRICEASC (Pagenum *
5)-4, Pagenum * 5);
List<product> news = new list<product> ();
for (int i =0 i <5; i++)
{
Dataset1.productrow row = Data[i];
string s = Link.toproduct (row.productid.tostring ());
News.add (new Product ()
{
Name = Row.name,
Description = Row.description,
Price = Row.price.tostring (),
thumbnail = Row.thumbnail,
Path = s
});
}
System.web.script.serialization.javascriptserializer JSS
= new System.web.script.serialization.javascriptserializer ();
Context.Response.Write (News) (jss.serialize);
}
}
public void ProcessRequest (HttpContext context)
{
Context.response.contenttype = "Text/plain";
String action = context.request["Action"];
if (action = = "GetPage")
{
int allcount = new
Dataset1tableadapters.producttableadapter (). GetCount (). value;
Context.Response.Write (Allcount);
}
else if (action = = "GETPAGEDATEASC")
{
GetPage ("GETPAGEDATEASC", context);
}
else if (action = = "Getpagedatedesc")
{
GetPage ("Getpagedatedesc", context);
}
}
public bool IsReusable
{
Get
{
return false;
}
}
}
public class product
{
public string name {set;
public string Description {set;
public string Price {set;
public string thumbnail {set;
public string Path {set;
}
HTML Code//http://www.3ppt.com/design/asp Tutorial x/38279.html
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<title></title>
<link href= "App_themes/balloonshopdefault/balloonshop.css Tutorial"
Rel= "stylesheet" type= "Text/css"/>
<link href= " Pagination.css "rel=" stylesheet "type=" Text/css "/>
<script src = "New Folder 1/jscript.js" Type= "Text/javascript"
</script>< Script src= "new Folder 1/jquery.pagination.js"
Type= "Text/javascript" ></script>
<script type= "text /javascript
function Createlink () {
$ ("#pagination a" ). Each (function (i) {
if (!isnan (parseint (this.innerhtml)) {
This.href = "/balloonshop/balloons-for-
Children/message-balloons/page= "+ parseint (this.innerhtml);
}
});
}
var data;
$ (function () {
$.post ("Handler.ashx", {"Action": "GetPage"}, function
(data123, status) {
data=data123;
InitData (0);
});
});
function Pageselectcallback (page_id, JQ) {
InitData (page_id);
return false;
};
function InitData (pageindx) {
$.post ("Handler.ashx", {"Action"): "Getpagedate",
"Pagenum": Pageindx}, function (data, status) {
if (status = = "Success") {
var datas = $.parsejson (data);
$ ("#myul"). empty ();
for (var i = 0; i < datas.length; i++) {
var p = datas[i];
var li = $ ("<li>" + "<h3
class= ' ProductTitle ' > <a href= ' "+ P.path +" ' > "+ p.name +" </a>
+
"<a href= '" + P.path
+ "' >" + "
+p.description+ "<p
class= ' detailsection ' >+ Price: "+p.price+" </p></li>);
$ ("#myul"). Append (LI);
}
};
});
$ ("#pagination"). Pagination (data, {
Callback:pageselectcallback,
Prev_text: ' << prev ',
Next_text: ' next page >> ',
Items_per_page:5,
Num_display_entries:4,
Current_page:pageindx,
Num_edge_entries:1
});
Createlink ();
}
</script>
</head>
<body>
<a href= "Catalog.aspx" ></a>
<ul style= "List-style-type:none" id= "Myul" ></ul>
<div id= "pagination" class= "Digg" style= "Float:left"/>
</body>
</html>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<title></title>
<link href= "App_themes/balloonshopdefault/balloonshop.css"
Rel= "stylesheet" type= "Text/css"/>
<link href= " Pagination.css "rel=" stylesheet "type=" Text/css "/>
<script src = "New Folder 1/jscript.js" Type= "Text/javascript"
</script>< Script src= "new Folder 1/jquery.pagination.js"
Type= "Text/javascript" ></script>
<script type= "text /javascript
function Createlink () {
$ ("#pagination a" ). Each (function (i) {
if (!isnan (parseint (this.innerhtml)) {
This.href = "/balloonshop/balloons-for-
Children/message-balloons/page= "+ parseint (this.innerhtml);
}
});
}
var data;
$ (function () {
$.post ("Handler.ashx", {"Action": "GetPage"}, function
(data123, status) {
data=data123;
InitData (0);
});
});
function Pageselectcallback (page_id, JQ) {
InitData (page_id);
return false;
};
function InitData (pageindx) {
$.post ("Handler.ashx", {"Action"): "Getpagedate",
"Pagenum": Pageindx}, function (data, status) {
if (status = = "Success") {
var datas = $.parsejson (data);
$ ("#myul"). empty ();
for (var i = 0; i < datas.length; i++) {
var p = datas[i];
var li = $ ("<li>" + "<h3
class= ' ProductTitle ' > <a href= ' "+ P.path +" ' > "+ p.name +" </a>
+
"<a href= '" + P.path
+ "' >" + "
+p.description+ "<p
class= ' detailsection ' >+ Price: "+p.price+" </p></li>);
$ ("#myul"). Append (LI);
}
};
});
$ ("#pagination"). Pagination (data, {
Callback:pageselectcallback,
Prev_text: ' << prev ',
Next_text: ' next page >> ',
Items_per_page:5,
Num_display_entries:4,
Current_page:pageindx,
Num_edge_entries:1
});
Createlink ();
}
</script>
</head>
<body>
<a href= "Catalog.aspx" ></a>
<ul style= "List-style-type:none" id= "Myul" ></ul>
<div id= "pagination" Clas solution:
(Change the DropDownList to a client HTML control select and then store it with Ajax, there's no mistake
, but the form has a lot of data to submit, so the client-side HTML control is not considered
1. <%@ page language= "C #" autoeventwireup= "true" on pages
Add codefile= "Default.aspx.cs" inherits= "_default"%>
Enableeventvalidation= "false";
2, add hidden fields in the page <input type= "hidden" id= "inputcity" runat= "Server"/>
, and then use JS to assign the value of the DropDownList selection to the hidden field,
This allows the background to read the value of the hidden field through Inputcity.value, which is the choice of the provinces and cities
Value of
s= "Digg" style= "Float:left"/>
</body>