• Axial:用.NET语言来写JavaScript代码


    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下载源代码,里面包含详细的代码示例。

  • 相关阅读:
    react 给选中的li添加样式
    纯css实现移动端横向滑动列表
    从一个Git仓库转移到另外一个仓库
    create-react-app 创建react项目 多页面应用
    JetBrains出品,一款好用到爆的数据库工具
    gloox环境搭建并运行example(小白教程,有图版本)
    Dubbo服务注册原理
    永久解决 matplotlib 图例中文方块错误
    对称二叉树
    SpringBoot运行原理
  • 原文地址:https://www.cnblogs.com/MaxIE/p/1605947.html
Copyright © 2020-2023  润新知