• asp.net 自定义控件 嵌入资源文件 备忘


    要想在自定义用户控件中嵌入资源,从以下几个步骤入手:

    1.在AssemblyInfo.cs中注册资源,文件夹层级用点隔开。例如:

    [assembly: System.Web.UI.WebResource("FirsteLite.OMS.Checking.UserControls.test.jpg", "image/jpg")]

    2.修改资源文件的"生成操作"的值为“嵌入的资源"。

    3.在代码里引用的时候可以用Page.ClientScript.GetWebResourceUrl来获取访问地址。例如:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace FirsteLite.OMS.Checking.UserControls
    {
        public class MarkingButton : System.Web.UI.WebControls.LinkButton
        {
            protected override void OnPreRender(EventArgs e)
            {
                this.Style.Add("background-image", Page.ClientScript.GetWebResourceUrl(this.GetType(), "FirsteLite.OMS.Checking.UserControls.test.jpg"));
                base.OnPreRender(e);
            }
        }
    }

    4.如果是js可能还要在页面动态引入。例如:

    protected override void OnPreRender(EventArgs e)
            {
                Page.ClientScript.RegisterClientScriptInclude("WdatePicker", GetResUrl("WdatePicker.js"));
    
                base.OnPreRender(e);
            }
  • 相关阅读:
    python RabbitMQ队列/redis
    python 协程
    Python 线程
    Python Socket网络编程
    Python 面向对象编程进阶
    Python 面向对象
    python 模块
    Python 迭代器&生成器&装饰器
    Python 集合操作
    Java多态--构造方法的内部方法多态
  • 原文地址:https://www.cnblogs.com/nanfei/p/5948960.html
Copyright © 2020-2023  润新知