asp.net 自訂控制項 嵌入資源檔 備忘

來源:互聯網
上載者:User

標籤:

要想在自訂使用者控制項中嵌入資源,從以下幾個步驟入手:

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);        }

 

asp.net 自訂控制項 嵌入資源檔 備忘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.