Axial:用.NET語言來寫JavaScript代碼

來源:互聯網
上載者:User

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下載原始碼,裡麵包含詳細的程式碼範例。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.