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

  • 相关阅读:
    HTML5项目笔记7:使用HTML5 WebStorage API构建与.NET对应的会话机制 Hello
    论设计模式和分析模式
    昨天我做了点什么事情啊?
    时间,时间,还是时间
    人生需要规划
    突然想起今天的博客汇报没写
    昨天看了熊猫大侠
    双休日往往会忘了写日志
    老婆说我是缺心眼!
    要下班了才想起没写报告
  • 原文地址:https://www.cnblogs.com/cn2758/p/4683545.html
Copyright © 2011-2022 走看看