Now. Many developers are already using the WebResource functionality of ASP.NET 2.0. WebResource allows us to embed resources into assemblies. Includes images, text, etc.
When introducing WebResource, we have to introduce WebResource.axd. Let's take a look at
script language="javascript" src="WebResource.axd?a=s&r=WebUIValidation.js&t=631944362841472848" type="text/javascript"></script >At present, I found that the parameters of webResource.axd are different from the current version. Introducing properties in an earlier article:
a assembly name
r resource file name
t The time when the assembly was last modified
webResource.axd is just a mapping in ISAPI. You can also use IhttpHandler. <add verb="GET" path="WebResource.axd" type="System.Web.Handlers.AssemblyResourceLoader" /> webResource.axd uses the AssemblyResourceLoader class to customize processing of HTTP requests, and identifies which program is coming from based on the program passed by the query. Which resource to get in the assembly.
The following uses the spinner control as an example.
Usage steps:
Add the resource to be embedded (such as an image) to the item. In the resource manager, click File, select embedded resource in the build action in the property window.
Add the following files to your assessbly.cs file
[assembly: WebResource("Obies.Web.UI.WebControls.NumericTextBox.js", "application/x-javascript")]
[assembly: WebResource("Obies.Web.UI.WebControls.NumericTextBox_Silver_BtnUp.gif", "image/gif")] Please note the WebResourceAttribute format:
[assembly: WebResourceAttribute("MyNameSpaces.Resources.MyImage.gif", "image/gif")]
In the CONTROL source code. You need to use the following code to get the image
// get WebResource URLs for the embedded gif images
String BtnUpImgSrc = this.Page.ClientScript.GetWebResourceUrl(typeof(NumericTextBox),
"Obies.Web.UI.WebControls.NumericTextBox_" + this.ImageSet.ToString() + "_BtnUp.gif");GetWebResourceUrl method:Gets a URL reference to a server-side resource. )
I found it in an earlier version. Its usage is: this.page.GetWebResourceUrl
The above code gets the image name from the specified assembly: Obies.Web.UI.WebControls.NumericTextBox_" + this.ImageSet.ToString() + "_BtnUp.gif, it What is returned is the URL reference address of a server-side resource. Similar to:
WebResource.axd?d=gWYJBlnQKynoTePlJ34jxyoSpR2Rh9lpYd8ZrSl0&t=632812333820000000In
addition, MS provides a Header class. The Header class mainly operates on <Head runat="server"></head> in HTML pages. Including Title, etc. Haha. It will be very easy to modify the title of a page in the future.
this.Header.Title = "This is the new page title.";
Add CSS style (style attribute) Style style = new Style();
style.ForeColor = System.Drawing.Color.Navy;
style.BackColor = System.Drawing.Color.LightGray;
// Add the style to the header for the body of the page
this.Header.StyleSheet.CreateStyleRule(style, null, "body");
protected override void OnPreRender (EventArgs e) {
// get a WebResource URL for the core JS script and register it
this.Page.ClientScript.RegisterClientScriptResource(typeof(NumericTextBox),
"Obies.Web.UI.WebControls.NumericTextBox.js");
// get a WebResource URL for the embedded CSS
String css = this.Page.ClientScript.GetWebResourceUrl (typeof(NumericTextBox),
"Obies.Web.UI.WebControls.NumericTextBox_" + this.ImageSet + ".css");
// register the CSS
// this.Page.StyleSheetTheme = css;
//this.Page.Header.LinkedStyleSheets.Add (css);
//Earlier version of the method? It can only be solved with the following code
HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", css);
this.Page.Header.Controls.Add(link);
}
Here is a screenshot of
how to use the spinner control:
<%@ register tagprefix="cc" namespace="Obies.Web.UI.WebControls" assembly="Obies.Web.UI.WebControls" %>
<cc:NumericTextBox width="50" ImageSet="Silver" length=" 2" runat="server" id="NumericTextBox1"
maxvalue="10" minvalue="0"></cc:NumericTextBox>
<cc:NumericTextBox width="50" ImageSet="Green" length="2" runat="server" id="NumericTextBox2"
maxvalue="10" minvalue="0"></cc:NumericTextBox>
Source address: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
dnvs05/html/webresource.asp
Due to some problems with the original code, many features are not supported by the latest VS2005. So modifications were made.
Source code download: