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.
script language="javascript" src="WebResource.axd?a=s&r=WebUIValidation.js&t=631944362841472848 " type="text/javascript">Currently I found that the parameters of webResource.axd are different from the current version. In an earlier article, attributes were introduced:
a Assembly name
r Resource file name
t Assembly last modified time
webResource.axd is just one in ISAPI mapping. You can also use IhttpHandler.
The following uses the fine-tuning control as an example.
Usage steps:
Add the resources to be embedded (such as images) to the item
In the resource manager, click the file, select embedded resource in the build action in the property window (property window) (embedded resource).
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")]
is in the CONTROL source code. You need to use the following code to get the images
// 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.(Gets a URL reference to a server-side resource)
I found that in in earlier versions. 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, which returns the URL reference address of a server-side resource. Similar to:
WebResource.axd?d=gWYJBlnQKynoTePlJ34jxyoSpR2Rh9lpYd8ZrSl0&t=632812333820000000
In addition, MS provides a Header class. The Header class mainly operates on
in HTML pages. Including Title etc.// 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);
//早期版本的方法?只能用下面的代码来解决了
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);
}
下面是微调控件的截图
使用方法:
<%@ register tagprefix="cc" namespace="Obies.Web.UI.WebControls" assembly="Obies.Web.UI.WebControls" %>
来源地址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
dnvs05/html/webresource.asp
由于原来的代码有点问题,很多特性都是最新VS2005不支持的。所以进行了修改。
源码下载:http://www.cnblogs.com/Files/cnzc/PostWebFormBetweenFrames.zip
在写这篇文章查了很多资料。也尝试用心去写。但总感觉写的不是很好。网上也有相关的webresource的介绍。但发现很多都是目前最新版本不支持的。不知道是不是以前ASP.NET2.0早期版本。所以才进行了简单的修改。
以后在努力了。
The above is the detailed content of ASP.NET2.0 WebRource, developing spinner control. For more information, please follow other related articles on the PHP Chinese website!