Ajax Simple Application code

Source: Internet
Author: User
Tags httpcontext prev serialization

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&lt;product&gt; news = new list&lt;product&gt; ();


for (int i = (Pagenum * 5)-4; I &lt;= 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&lt;product&gt; news = new list&lt;product&gt; ();


for (int i =0 i &lt;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 &lt; datas.length; i++) {


var p = datas[i];


var li = $ ("&lt;li&gt;" + "&lt;h3

class= ' ProductTitle ' > <a href= ' "+ P.path +" ' > "+ p.name +" </a>

+
"<a href= '" + P.path

+ "' >" + "
+p.description+ "<p

class= ' detailsection ' &gt;+ Price: "+p.price+" &lt;/p&gt;&lt;/li&gt;);














$ ("#myul"). Append (LI);
















}

};


});

$ ("#pagination"). Pagination (data, {


Callback:pageselectcallback,


Prev_text: ' &lt;&lt; prev ',


Next_text: ' next page &gt;&gt; ',


Items_per_page:5,


Num_display_entries:4,


Current_page:pageindx,


Num_edge_entries:1


});


Createlink ();


}





&lt;/script&gt;


&lt;/head&gt;


&lt;body&gt;


&lt;a href= "Catalog.aspx" &gt;&lt;/a&gt;


&lt;ul style= "List-style-type:none" id= "Myul" &gt;&lt;/ul&gt;


&lt;div id= "pagination" class= "Digg" style= "Float:left"/&gt;


&lt;/body&gt;


&lt;/html&gt;

<!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 &lt; datas.length; i++) {


var p = datas[i];


var li = $ ("&lt;li&gt;" + "&lt;h3

class= ' ProductTitle ' > <a href= ' "+ P.path +" ' > "+ p.name +" </a>

+
"<a href= '" + P.path

+ "' >" + "
+p.description+ "<p

class= ' detailsection ' &gt;+ Price: "+p.price+" &lt;/p&gt;&lt;/li&gt;);














$ ("#myul"). Append (LI);
















}

};


});

$ ("#pagination"). Pagination (data, {


Callback:pageselectcallback,


Prev_text: ' &lt;&lt; prev ',


Next_text: ' next page &gt;&gt; ',


Items_per_page:5,


Num_display_entries:4,


Current_page:pageindx,


Num_edge_entries:1


});


Createlink ();


}





&lt;/script&gt;


&lt;/head&gt;


&lt;body&gt;


&lt;a href= "Catalog.aspx" &gt;&lt;/a&gt;


&lt;ul style= "List-style-type:none" id= "Myul" &gt;&lt;/ul&gt;


&lt;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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.