Axial 是CodePlex上一個開源項目,使用它我們可以以C#或VB.NET的方式來實現JavaScript功能,然後它會自動將相應的JavaScript輸出到用戶端。一些表單控制項的輸入驗證、一些JS特效以及Ajax等等,我們都可以用它來實現。Axial現在還封裝了jQuery,使我們可以用C#或者VB.NET來使用jQuery。
Axial包含幾個伺服器控制項:
- WFServerScript
- WFScript
- WFValidator
- WFStartupScript
- WFClass
- Canvas
- WFScriptButton
Axial的使用很簡單:
1、添加Axial.dll引用,並將Axial控制項添加到控制項工具箱中
2、在後台寫相關JavaScript的.NET方法,方法必須為public
using Axial;
using Axial.jQuery;
using Axial.DOM;
namespace AxialWeb
{
public partial class jQueryTest : System.Web.UI.Page
{
protected void HtmlTheDivs() {
JQuery.jQuery("div.empty").html("in a div");
JQuery.get("viaajax.txt", "", (response) => { JQuery.jQuery("div.empty:first").html((string)response); });
JQuery.jQuery("div.notempty").children().html("when two divs love each other very much");
JQuery.jQuery("div.notempty").children().css("padding", "3px");
JQuery.jQuery("div.notempty").children().each(AlertPadding);
}
protected void AlertPadding() {
Window.Alert(JQuery.This.css("padding"));
}
}
}
3、在前台ASPX頁面放置一個Axial控制項,設定MethodName屬性
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>jQuery Test</title>
<script type="text/javascript" src="jquery-1.2.3.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div class="empty" style="border: 1px solid red;"></div>
<div class="empty" style="border: 1px solid blue;"></div>
<div class="notempty" style="border: 1px solid green;">
<div style="border: 1px solid purple;"></div>
</div>
<asp:Button runat="server" ID="btnRun" Text="Run" OnClientClick="HtmlTheDivs(); return false;" />
<axial:WFScript runat="server" ID="wfsHTD" MethodName="HtmlTheDivs" />
</form>
</body>
</html>
關於Axial的詳細使用,請到CodePlex下載原始碼,裡麵包含詳細的程式碼範例。