AjaxPro2中UpdatePanel控件的使用

定时刷新示例: 
ASPX页面

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="caipiao_test"  %>

<% @ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace
="System.Web.UI" TagPrefix="asp" 
%>
 
<! 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  runat ="server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
    
< asp:ScriptManager  runat =server  ID ="script21"  EnablePageMethods =true ></ asp:ScriptManager >
    
< asp:UpdatePanel  runat =server  ID ="UpdatePanel1" >
    
< ContentTemplate >
        
< asp:GridView  ID ="GridView1"  runat ="server"  AutoGenerateColumns ="False"  CellPadding ="4"
            ForeColor
="#333333"  GridLines ="None"  Width ="374px" >
        
< FooterStyle  BackColor ="#507CD1"  ForeColor ="White"  Font-Bold ="True" ></ FooterStyle >
        
< Columns >
        
< asp:BoundField  DataField ="u_username_s"  HeaderText ="用户名" ></ asp:BoundField >
        
< asp:BoundField  DataField ="u_pwd_s"  HeaderText ="密码" ></ asp:BoundField >
        
< asp:BoundField  DataField ="u_balance_d"  HeaderText ="金额" ></ asp:BoundField >
        
</ Columns >

        
< RowStyle  BackColor ="#EFF3FB" ></ RowStyle >

        
< EditRowStyle  BackColor ="#2461BF" ></ EditRowStyle >

        
< SelectedRowStyle  BackColor ="#D1DDF1"  ForeColor ="#333333"  Font-Bold ="True" ></ SelectedRowStyle >

        
< PagerStyle  BackColor ="#2461BF"  ForeColor ="White"  HorizontalAlign ="Center" ></ PagerStyle >

        
< HeaderStyle  BackColor ="#507CD1"  ForeColor ="White"  Font-Bold ="True" ></ HeaderStyle >

        
< AlternatingRowStyle  BackColor ="White" ></ AlternatingRowStyle >
        
</ asp:GridView >
        
</ ContentTemplate >
        
< Triggers >
        
< asp:AsyncPostBackTrigger  EventName ="Tick"  ControlID ="t"   />
        
</ Triggers >
    
</ asp:UpdatePanel >
    
< asp:Timer  ID ="t"  runat =server  Interval ="5000"  OnTick ="t_Tick" ></ asp:Timer >
    
</ div >
    
</ form >
</ body >
</ html >

 CS页面:

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  System.Windows.Forms.Design;

public   partial   class  caipiao_test : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            dataLoad();
        }

    }


    
private void dataLoad()
    
{
        Worker.BLL.CaiPiao.cp_member bll 
= new Worker.BLL.CaiPiao.cp_member();
        DataSet ds 
= bll.GetList("");
        GridView1.DataSource 
= ds;
        GridView1.DataBind();
    }


    
protected void t_Tick(object sender, EventArgs e)
    
{
        dataLoad();
    }

}

另外在Bin目录下还要加入AjaxPro.2.dll,System.Web.Extensions.dll,System.Web.Extensions.Design.dll(附件发不上来...)

 

在webconfig.xml中也要配置:

在system.web节点中加入

 

< httpHandlers >
      
< add  verb ="POST,GET"  path ="ajaxpro/*.ashx"  type ="AjaxPro.AjaxHandlerFactory, AjaxPro.2" />
      
< remove  verb ="*"  path ="*.asmx" />
      
< add  verb ="*"  path ="*.asmx"  validate ="false"  type ="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      
< add  verb ="*"  path ="*_AppService.axd"  validate ="false"  type ="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      
< add  verb ="GET,HEAD"  path ="ScriptResource.axd"  type ="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  validate ="false" />       
    
</ httpHandlers >

 

 

不定时刷新示例:

  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>无标题页</title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server"> 
  9. <asp:ScriptManager ID="ScriptManager1" runat="server"> 
  10. </asp:ScriptManager> 
  11. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> 
  12. <ContentTemplate> 
  13. <% =DateTime.Now.ToString()%> 
  14. </ContentTemplate> 
  15. <Triggers> 
  16. <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" /> 
  17. </Triggers> 
  18. </asp:UpdatePanel> 
  19. <br /> 
  20. <% =DateTime.Now.ToString()%> 
  21. <asp:Button ID="Button2" runat="server" Text="Button" /> 
  22. </form>
  23. </body>
  24. </html>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值