MagicAjax.Net的使用要点和简单例子

        首先是怎么使用MagicAjax.Net。这个其实很多人多讲过了,我这里重复一下。
        首先还是新建个项目,然后添加引用:MagicAjax.dll。然后在配置文件Web.config中放入以下配置:
None.gif < httpModules >
None.gif    
< add name = " MagicAjax "  type = " MagicAjax.MagicAjaxModule, MagicAjax "   />  
None.gif
</ httpModules >
这样我们就能在我们的程序中使用Ajax了。哦,对了,忘了要用ajax技术的.aspx文件中还要加上这句话:
None.gif <% @ Register TagPrefix = " ajax "  Namespace = " MagicAjax.UI.Controls "  
None.gifAssembly
= " MagicAjax "   %>
现在就没有问题拉^_^
        接着是一个简单的应用。研究一些新技术我总喜欢用一些非常简单的例子,毕竟重点是弄清楚这个技术的用法,所以例子不是很复杂。
        首先是.aspx文件的代码:
None.gif <% @ Page language = " c# "  Codebehind = " WebForm1.aspx.cs "  AutoEventWireup = " false "  Inherits = " example.WebForm1 "   %>
None.gif
<% @ Register TagPrefix = " ajax "  Namespace = " MagicAjax.UI.Controls "  
None.gifAssembly
= " MagicAjax "   %>
None.gif
<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.0 Transitional//EN "   >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > WebForm1 </ title >
None.gif        
< meta name = " GENERATOR "  Content = " Microsoft Visual Studio .NET 7.1 " >
None.gif        
< meta name = " CODE_LANGUAGE "  Content = " C# " >
None.gif        
< meta name = " vs_defaultClientScript "  content = " JavaScript " >
None.gif        
< meta name = " vs_targetSchema "  content = " http://schemas.microsoft.com/intellisense/ie5 " >
None.gif    
</ HEAD >
None.gif    
< body MS_POSITIONING = " GridLayout " >
None.gif        
< form id = " Form1 "  method = " post "  runat = " server " >
None.gif            
< ajax:AjaxPanel id = " AjaxPanel1 "  runat = " server " >
None.gif                
< asp:DataGrid id = " mygrid "  Runat = " server " ></ asp:DataGrid >
None.gif                
< asp:Button id = " Button1 "  style = " Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 192px "  runat = " server "
None.gif                Text
= " 确定 "  Width = " 96px "  BackColor = " Transparent " ></ asp:Button >
None.gif                
< asp:Button id = " Button2 "  style = " Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 192px "  runat = " server "
None.gif                Text
= " 确定2 "  Width = " 104px "  BackColor = " Transparent " ></ asp:Button >
None.gif            
</ ajax:AjaxPanel >
None.gif            
None.gif            
None.gif            
< asp:DataGrid id = " DataGrid1 "  style = " Z-INDEX: 103; LEFT: 368px; POSITION: absolute; TOP: 264px "
None.gif                runat
= " server "  Width = " 240px "  Height = " 248px " ></ asp:DataGrid >
None.gif            
< asp:Button id = " Button3 "  style = " Z-INDEX: 104; LEFT: 440px; POSITION: absolute; TOP: 576px "  runat = " server "
None.gif                Text
= " Button "  Width = " 104px "  Height = " 32px " ></ asp:Button >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif
        MagicAjax把要实现无刷的控件放在一个AjaxPanel中。在这里,我要用按钮控制DataGrid控件的显示内容,所以我把DataGrid控件和两个Button控件放在AjaxPanel中。
None.gif < ajax:AjaxPanel id = " AjaxPanel1 "  runat = " server " >
None.gif                
< asp:DataGrid id = " mygrid "  Runat = " server " ></ asp:DataGrid >
None.gif                
< asp:Button id = " Button1 "  style = " Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 192px "  runat = " server "
None.gif                Text
= " 确定 "  Width = " 96px "  BackColor = " Transparent " ></ asp:Button >
None.gif                
< asp:Button id = " Button2 "  style = " Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 192px "  runat = " server "
None.gif                Text
= " 确定2 "  Width = " 104px "  BackColor = " Transparent " ></ asp:Button >
None.gif            
</ ajax:AjaxPanel >
        接下来是后台代码:
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
namespace  example
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid mygrid;
InBlock.gif        
protected System.Web.UI.WebControls.Button Button1;
InBlock.gif        
protected System.Web.UI.WebControls.Button Button2;
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid DataGrid1;
InBlock.gif        
protected System.Web.UI.WebControls.Button Button3;
InBlock.gif        
protected MagicAjax.UI.Controls.AjaxPanel AjaxPanel1;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            ArrayList a = new ArrayList();
InBlock.gif            a.Add(
"a");
InBlock.gif            a.Add(
"b");
InBlock.gif            a.Add(
"c");
InBlock.gif
InBlock.gif            mygrid.DataSource 
= a;
InBlock.gif            mygrid.DataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Button1.Click += new System.EventHandler(this.Button1_Click);
InBlock.gif            
this.Button2.Click += new System.EventHandler(this.Button2_Click);
InBlock.gif            
this.Button3.Click += new System.EventHandler(this.Button3_Click);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void Button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ArrayList a 
= new ArrayList();
InBlock.gif            a.Add(
"aa");
InBlock.gif            a.Add(
"bb");
InBlock.gif            a.Add(
"cc");
InBlock.gif
InBlock.gif            mygrid.DataSource 
= a;
InBlock.gif            mygrid.DataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void Button2_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ArrayList a 
= new ArrayList();
InBlock.gif            a.Add(
"aaa");
InBlock.gif            a.Add(
"bbb");
InBlock.gif            a.Add(
"ccc");
InBlock.gif
InBlock.gif            mygrid.DataSource 
= a;
InBlock.gif            mygrid.DataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void Button3_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ArrayList a 
= new ArrayList();
InBlock.gif            a.Add(
"e");
InBlock.gif            a.Add(
"f");
InBlock.gif            a.Add(
"g");
InBlock.gif
InBlock.gif            DataGrid1.DataSource 
= a;
InBlock.gif            DataGrid1.DataBind();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
        其实这个程序很简单,就是无刷新更新DataGrid控件的显示内容。为了清楚的比较刷新和无刷新的效果,我还加了个需要刷新的DataGrid控件。虽然这个刷新的速度比较快,看起来不是很明显,但你注意看的话还是发现它是刷新了的。

转载于:https://www.cnblogs.com/fxb248/archive/2006/04/20/380233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值