zoukankan      html  css  js  c++  java
  • WebResource.axd文件的配置和使用

    很多ASP.NET server控件都需要另外的外部资源来实现某些功能,WebResource.axd就是将一些js,jpg,bmp等封装或叫植入到类库里面。

    使用WebResource.axd需要注意几点

    1.在类库中注册js脚本资源

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI;
    
    [assembly: WebResource("WebResource.dome.js", "text/javascript", PerformSubstitution = true)]
    namespace WebResource
    {
        public class WebDemo
        {
            public WebDemo(System.Web.UI.Page p)
            {
                string key = base.GetType().ToString();
                if (!p.ClientScript.IsClientScriptBlockRegistered(key))
                {
                    p.ClientScript.RegisterClientScriptResource(typeof(WebDemo), "WebResource.dome.js");   //这时就是将js文件注册到页面,,注意js文件名称的写法:命名空间+文件夹名子(如果没有放在文件夹中可以省略)+文件名称
                }
            }
        }
    }
    dome.js:
    function HellowWeb() {
        alert("我来自类库中的js文件");
    } 
    
    dome.js需要修改属性,“生成操作”=“嵌入的资源”
    2.在要使用的页面
    using WebResource;

    protected void Page_Load(object sender, EventArgs e) { //注册js脚本 new WebDemo(this); }

      

        <form id="form1" runat="server">
            <input id="Button" onclick="HellowWeb();" type="button" value="button" />
        </form>
    

    3.修改Config文件

    <pages validateRequest="false" enableEventValidation="false" pageBaseType="WebResource.WebDemo,WebResource">
    </pages>

    <httpHandlers>   <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true"/> </httpHandlers>

      

    参考:

    http://blog.csdn.net/kingmax54212008/article/details/9917409

    https://msdn.microsoft.com/zh-cn/library/system.web.ui.clientscriptmanager.registerclientscriptresource.aspx

  • 相关阅读:
    gjrand 4.0 发布,C语言的伪随机数生成器
    Kite 0.2.0 发布,编程语言
    IBM/DW C++11 标准新特性:Defaulted 和 Deleted 函数
    Apache Solr 3.6.2 发布
    bitmap 内存溢出处理
    Qtractor 0.5.7 发布,多轨音序生成器
    CUBRID Node.js Driver 1.1 发布
    OrientDB 1.3.0 发布,基于文档的数据库
    linux centos 下面httpd支持的svn 服务器端安装
    iptables 1.4.17 发布,Linux防火墙
  • 原文地址:https://www.cnblogs.com/cn2758/p/4683545.html
Copyright © 2011-2022 走看看