MagicAjax使用简介
MagicAjax使用简介
MagicAjax 的下载地址: http://www.magicajax.net/
当前的最新版本是 0.3.0,针对.NET 1.1 和 .NET 2.0 有两个不同版本下载。
1、在当前的WEB项目中添加 MagicAjax.dll 引用
这个文件在下载的zip压缩的 bin 目录里。
2、在WEB项目的配置文件 web.config 中增加这样一句
<httpModules>
<add name="MagicAjax" type="MagicAjax.MagicAjaxModule, MagicAjax" />
</httpModules>
<add name="MagicAjax" type="MagicAjax.MagicAjaxModule, MagicAjax" />
</httpModules>
把它放在 <system.web> ..... </system.web> 里面
3、在aspx页面文件中最前面添加
<%@ Register TagPrefix="ajax" Namespace="MagicAjax.UI.Controls" Assembly="MagicAjax" %>
4、将aspx页面中想实现无页面刷新更新数据的控件,放在这一个AjaxPanel容器中,使用上和asp.net自带的Panel控件没什么差别。
<ajax:AjaxPanel id="AjaxPanel1" runat="server">
</ajax:AjaxPanel>
</ajax:AjaxPanel>
举例:
-------------页面文件---------------
<%@ Register TagPrefix="ajax" Namespace="MagicAjax.UI.Controls" Assembly="MagicAjax" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<ajax:ajaxpanel ID="Ajaxpanel1" runat="server">
<asp:Button id="ShowTime" runat="server" Text="Show server's date & time"></asp:Button>
<asp:Label id="lblShowTime" runat="server" ForeColor="White" BackColor="Blue"></asp:Label>
</ajax:ajaxpanel>
</form>
</body>
</HTML>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<ajax:ajaxpanel ID="Ajaxpanel1" runat="server">
<asp:Button id="ShowTime" runat="server" Text="Show server's date & time"></asp:Button>
<asp:Label id="lblShowTime" runat="server" ForeColor="White" BackColor="Blue"></asp:Label>
</ajax:ajaxpanel>
</form>
</body>
</HTML>
-------------代码文件-------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button ShowTime;
protected System.Web.UI.WebControls.Label lblShowTime;
protected MagicAjax.UI.Controls.AjaxPanel Ajaxpanel1;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web 窗体设计器生成的代码
private void ShowTime_Click(object sender, System.EventArgs e)
{
lblShowTime.Text = DateTime.Now.ToString();
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button ShowTime;
protected System.Web.UI.WebControls.Label lblShowTime;
protected MagicAjax.UI.Controls.AjaxPanel Ajaxpanel1;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web 窗体设计器生成的代码
private void ShowTime_Click(object sender, System.EventArgs e)
{
lblShowTime.Text = DateTime.Now.ToString();
}
}
}
-----------------------------
posted on 2006-03-28 15:01 CrazyWill 阅读(1351) 评论(1) 编辑 收藏 举报