| 加入收藏| 设为首页| 联系我们

首页 站长学习 站长之家 源码下载 建站素材 书籍教程 常用工具
 您现在的位置: 动力中国 >> 网络编程 >> Ajax教程 >> 文章正文  
 结合MS AJAX将js文件编译到动态链接库
 

结合MS AJAX将js文件编译到动态链接库

http://www.domcn.org  文章来源:本站收藏  点击数:

  关键字:结合MS AJAX将js文件编译到动态链接库

为了使javascript代码不被窃取,我们可以将js文件编译成动态链接库(dll)文件。下面为了演示这一功能,创建了一个控件。

 程序代码:http://www.cnblogs.com/Files/hblynn/SampleControlsCS.rar

一、创建一个类库项目,命名为UpdateAnimate。

二、向项目中添加引用System.Web, System.Drawing, System.Web.Extensions

三、向项目中添加一个Jscript的文件UpdatePanelAnimation.js

四、向文件中添加如下代码:


BorderAnimation = function(color)
{
    this._color = color;
}

BorderAnimation.prototype =
{
    animate: function(panelElement)
    {
        var s = panelElement.style;
        s.borderWidth = 2px;
        s.borderColor = this._color;
        s.borderStyle = solid;

        window.setTimeout(
            function()
            {
            {
                s.borderWidth = 0;
            }
            },
            500);
    }
}


这段代码中,包含一段临时改变UpdatePanel控件样式的方法

 

五、解决方案资源管理器中,右键查看UpdatePanelAnimation.js的属性,把高级中的“生成操作”属性设置成“嵌入的资源”。

六、向项目中添加一个类CustomControl

七、替换类中的代码:

using System;
using System.Drawing;
using System.Web.UI;
using System.Web;
using System.Globalization;

namespace UpdateAnimate
{
    public class UpdatePanelAnimationWithClientResource : Control
    {
        private string _updatePanelID;
        private Color _borderColor;
        private Boolean _animate;
        public Color BorderColor
        {
            get
            {
                return _borderColor;
            }
            set
            {
                _borderColor = value;
            }
        }

        public string UpdatePanelID
        {
            get
            {
                return _updatePanelID;
            }
            set
            {
                _updatePanelID = value;
            }
        }

        public Boolean Animate
        {
            get
            {
                return _animate;
            }
            set
            {
                _animate = value;
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (Animate)
            {

                UpdatePanel updatePanel = (UpdatePanel)FindControl(UpdatePanelID);

                string script = String.Format(
                   CultureInfo.InvariantCulture,
                   @
Sys.Application.add_load(function(sender, args) {{
var {0}_borderAnimation = new BorderAnimation({1});   
var panelElement = document.getElementById({0});
     if (args.get_isPartialLoad()) {{
        {0}_borderAnimation.animate(panelElement);
    }}
}})
,
                   updatePanel.ClientID,
                   ColorTranslator.ToHtml(BorderColor));


                ScriptManager.RegisterStartupScript(
                    this,
                    typeof(UpdatePanelAnimationWithClientResource),
                    ClientID,
                    script,
                    true);
            }
        }
    }
}

 

 

八、向AssemblyInfo.cs文件中添加如下行:

[assembly: System.Web.UI.WebResource(UpdateAnimate.UpdatePanelAnimation.js, application/x-javascript)]

九、生成项目。

 

控件演示:

一、创建一个AJAX-enabled类型的网站项目。

二、向网站跟目录下添加bin目录。

三、从控件项目的bin\Debug或 bin\Release目录拷贝UpdateAnimate.dll到网站bin目录里。

四、替换Default.aspx的内容并运行程序:

 

  <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %>

<%@ Register TagPrefix=Samples Namespace=UpdateAnimate Assembly=UpdateAnimate %>

<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<script runat=server>

</script>

<html xmlns=http://www.w3.org/1999/xhtml>
<head id=Head1 runat=server>
    <title>ScriptReference</title>
</head>
<body>
    <form id=form1 runat=server>
        <div>
            <asp:ScriptManager ID=ScriptManager1
                                 EnablePartialRendering=True
                                 runat=server>
             <Scripts>
                <asp:ScriptReference Assembly=UpdateAnimate Name=UpdateAnimate.UpdatePanelAnimation.js />
             </Scripts>
            </asp:ScriptManager>


            <Samples:UpdatePanelAnimationWithClientResource
                     ID=UpdatePanelAnimator1
                     BorderColor=Green
                     Animate=true
                     UpdatePanelID=UpdatePanel1
                     runat=server >
            </Samples:UpdatePanelAnimationWithClientResource>
            <asp:UpdatePanel ID=UpdatePanel1
                               UpdateMode=Conditional
                               runat=server>
                <ContentTemplate>
                    <asp:Calendar ID=Calendar2
                                  runat=server>
                    </asp:Calendar>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
http://www.cnblogs.com/hblynn/archive/2007/02/01/637312.html


结合MS AJAX将js文件编译到动态链接库
  • 上一篇文章:

  • 下一篇文章:
  •  热门文章
    普通文章 电子邮件改头换面 四公司畅谈未
    普通文章 PC病毒史上最声名狼藉的八大病
    普通文章 Rails系统中的AJAX开发技术简析
    普通文章 基于ASP.NET AJAX框架实现表单
    普通文章 开发ASP.NET AJAX客户端定制行
    普通文章 用JFreeChart对JSP报表进行增强
    普通文章 SQL Server 2005上的CLR和ADO.
    普通文章 SQL Server 2005的XML支持机制
    普通文章 Firefox中标签式浏览技巧大全
    普通文章 Tomcat中的Session和Cookie大揭
     
     推荐文章
    推荐文章 把Google地图嵌入网页 就是这么
    推荐文章 迅雷搜索候选资源出错的解决
    推荐文章 轻松去除迅雷里的各种广告和资
    推荐文章 突破限制 免费领养到QQ空间五级
    推荐文章 Rational统一过程RUP贴近中小软
    推荐文章 构建自己的轻量级XML DOM分析程
    推荐文章 WPS Office 2007技巧:妙用配置
    推荐文章 Excel 2007:求余数函数实用进阶
    推荐文章 浅谈ASP.NET的Postback
    推荐文章 软件开发中项目需求管理简述
     
     相关文章
    没有相关文章
    设为首页 | 加入收藏 | 广告合作 | 联系站长 | 版权申明 |
    动力中国为网友提供免费学习资料,可用资源,如果您认为我们的相关内容侵害到了您的权利请联系管理员
    Copyright © 2006-2008 domcn.org All Rights Reserved.