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