ASP. NET custom control Embedded Resource file Memo

Source: Internet
Author: User

To embed a resource in a custom user control, start with the following steps:

1. Register the resources in AssemblyInfo.cs, and the folder hierarchy is separated by dots. For example:

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

2. Modify the value of the build action for the resource file to "Embedded Resource".

3. You can use PAGE.CLIENTSCRIPT.GETWEBRESOURCEURL to obtain an access address when referencing in the code. For example:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacefirstelite.oms.checking.usercontrols{ Public classMarkingButton:System.Web.UI.WebControls.LinkButton {protected Override voidOnPreRender (EventArgs e) { This. Style.add ("Background-image", Page.ClientScript.GetWebResourceUrl ( This. GetType (),"FirsteLite.OMS.Checking.UserControls.test.jpg")); Base.        OnPreRender (e); }    }}

4. If it is JS may also be introduced dynamically on the page. For example:

protected Override void OnPreRender (EventArgs e)        {            Page.ClientScript.RegisterClientScriptInclude ("wdatepicker", Getresurl ( " Wdatepicker.js " ));             Base . OnPreRender (e);        }

ASP. NET custom control Embedded Resource file Memo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.