asp.net ajax 简单应用实例

asp教程.net文件

@ 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.网页特效serializer jss = new system.web.script.serialization.javascriptserializer();
            context.response.write(jss.serialize(news));
        }

        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(jss.serialize(news));
       
        }

     }
    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; get; }
    public string description { set; get; }
    public string price { set; get; }
    public string thumbnail { set; get; }
    public string path { set; get; }

}      

html代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <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="新文件夹1/jscript.js" type="text/javascript">
    </script><script src="新文件夹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></h3>" +
                                               "<a href='" + p.path + "'>" + "<img src=" + "productimages/" + p.thumbnail + " />" + "</a>"
                                             
                                             +p.description+"<p class='detailsection'>+ price:"+p.price+"</p></li>");
 
                                
                                         
   
                       $("#myul").append(li);
    
    
       
   
 

  
                   
                    }

                };

            });

            $("#pagination").pagination(data, {
                callback: pageselectcallback,
                prev_text: '<< 上一页',
                next_text: '下一页 >>',
                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">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <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="新文件夹1/jscript.js" type="text/javascript">
    </script><script src="新文件夹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></h3>" +
                                               "<a href='" + p.path + "'>" + "<img src=" + "productimages/" + p.thumbnail + " />" + "</a>"
                                             
                                             +p.description+"<p class='detailsection'>+ price:"+p.price+"</p></li>");
 
                                
                                         
   
                       $("#myul").append(li);
    
    
       
   
 

  
                   
                    }

                };

            });

 

            $("#pagination").pagination(data, {
                callback: pageselectcallback,
                prev_text: '<< 上一页',
                next_text: '下一页 >>',
                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>

时间: 2024-09-29 21:54:33

asp.net ajax 简单应用实例的相关文章

asp.net+ajax简单分页实例分析

本文实例讲述了asp.net+ajax简单分页实现方法.分享给大家供大家参考,具体如下: 这里涉及两个.aspx文件,一个叫Default.aspx,一个叫AjaxOperations.aspx,第一个用来显示一些测试数据,后一个用来对分页进行处理.js文件夹下面还有一个testJs.js的文件,它就是ajax操作的核心部分.不错,code is cheap.看代码: /*testJs.js*/ // 此函数等价于document.getElementById /document.all fun

asp.net+ajax简单分页实例分析_AJAX相关

本文实例讲述了asp.net+ajax简单分页实现方法.分享给大家供大家参考,具体如下: 这里涉及两个.aspx文件,一个叫Default.aspx,一个叫AjaxOperations.aspx,第一个用来显示一些测试数据,后一个用来对分页进行处理.js文件夹下面还有一个testJs.js的文件,它就是ajax操作的核心部分.不错,code is cheap.看代码: /*testJs.js*/ // 此函数等价于document.getElementById /document.all fun

AJAX简单应用实例-弹出层_应用技巧

function createobj() {  if (window.ActiveXObject) {          return(new ActiveXObject("Microsoft.XMLHTTP"));      }      else if (window.XMLHttpRequest) {          return(new XMLHttpRequest());      } } function personalInfo() {   var oBao=creat

AJAX简单异步通信实例分析_AJAX相关

本文实例讲述了AJAX简单异步通信的方法.分享给大家供大家参考.具体分析如下: 客户端:向服务器发出一个空请求. 代码如下: <html> <head> <title>XMLHttpRequest</title> <script language="javascript"> var xmlHttp; function createXMLHttpRequest(){ if(window.ActiveXObject) xmlHtt

asp.net实现简单分页实例_实用技巧

本文实例讲述了asp.net实现简单分页的方法.分享给大家供大家参考. 具体实现方法如下: 复制代码 代码如下: /// <summary> /// 分页内容 /// </summary> /// <param name="size">页面大小</param> /// <param name="count">页面数量</param> /// <param name="curren

asp.net 连接数据库简单应用实例

asp教程.net 连接数据库教程简单应用实例 1.需要使用时 new sqlconnection & open,使用完后 close & dispose,这种是最简单的,但是,性能不多说(有可能一个页面需要做100次重复操作). 如果有人使用 executereader 方法的话(未读完数据不能关闭 connection),项目庞大以后,这时如果有一处忘了 close & dispose,可能会影响系统的正常运行. 因为每次都是 new sqlconnection,所以不能扩展事

AJAX简单异步通信实例分析

本文实例讲述了AJAX简单异步通信的方法.分享给大家供大家参考.具体分析如下: 客户端:向服务器发出一个空请求. 代码如下: <html> <head> <title>XMLHttpRequest</title> <script language="javascript"> var xmlHttp; function createXMLHttpRequest(){ if(window.ActiveXObject) xmlHtt

ASP中的AJAX简单应用

Index.asp: 程序代码 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>AJAX简单应用</title> <script language="javascript"> //创建XMLHttpRequest对象 var request

ASP.NET AJAX入门系列(10):Timer控件简单使用

本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 1.添加新页面并切换到设计视图. 2.如果页面没有包含ScriptManager控件,在工具箱的AJAX Extensions标签下双击ScriptManager控件添加到页面中. 3.单击ScriptManager控件并双击UpdatePanel控件添加到页面中. 4.在UpdatePanel控件内单击并双击Timer控件添加到UpdatePanel中.Ti