現(xiàn)在。有許多開發(fā)人員已經(jīng)在使用asp.net2.0的webresource的功能了。webresource允許我們嵌入資源到程序集中。包括圖像,文本等。
在介紹webresource就不得不介紹一下webresource.axd,我們來看一下
script language="javascript" src="webresource.axd?a=s&r=webuivalidation.js&t=631944362841472848" type="text/javascript"></script>目前我發(fā)現(xiàn)webresource.axd的參數(shù)跟現(xiàn)在版本有屬不同。在早期文章介紹屬性:
a 程序集名稱
r 資源文件名稱
t 程序集最后修改的時間
webresource.axd只是isapi中的一個映射。你也可以在使用ihttphandler。<add verb="get" path="webresource.axd" type="system.web.handlers.assemblyresourceloader" /> webresource.axd是通過assemblyresourceloader類來自定義處理http請求,根據(jù)所query傳遞的程序來識別從哪個程序集中獲取哪個資源。
下面以微調(diào)控件為示例。
使用步驟:
添加要嵌入的資源(比如圖像)到項(xiàng)中
在資源管理器中,單擊文件,在property window(屬性窗口)中build action選擇embedded resource(嵌入資源)。
添加下列文件到你的assessbly.cs文件哪中
[assembly: webresource("obies.web.ui.webcontrols.numerictextbox.js", "application/x-javascript")]
[assembly: webresource("obies.web.ui.webcontrols.numerictextbox_silver_btnup.gif", "image/gif")]請注意webresourceattribute格式:
[assembly: webresourceattribute("mynamespaces.resources.myimage.gif", "image/gif")]
在control源碼當(dāng)中。你需要使用下面代碼來獲取圖像
// 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.(獲取對服務(wù)器端資源的 url 引用)
我發(fā)現(xiàn)在早期版本當(dāng)中。它的使用方法是:this.page.getwebresourceurl
上面代碼是從指定的程序集中當(dāng)中獲取圖像名稱:obies.web.ui.webcontrols.numerictextbox_" + this.imageset.tostring() + "_btnup.gif,它返回的是一個服務(wù)器端資源的url引用地址。類似于:
webresource.axd?d=gwyjblnqkynoteplj34jxyospr2rh9lpyd8zrsl0&t=632812333820000000
另外,ms提供一個header類。header類主要是對html頁面中的<head runat="server"></head>的操作。包括title等
呵呵。以后要修改一個頁面的標(biāo)題很很簡單了。
this.header.title = "this is the new page title.";
添加css樣式(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);
//早期版本的方法?只能用下面的代碼來解決了
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);
}
下面是微調(diào)控件的截圖
使用方法:
<%@ 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>
來源地址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
dnvs05/html/webresource.asp
由于原來的代碼有點(diǎn)問題,很多特性都是最新vs2005不支持的。所以進(jìn)行了修改。
源碼下載:http://www.cnblogs.com/files/cnzc/postwebformbetweenframes.zip
在寫這篇文章查了很多資料。也嘗試用心去寫。但總感覺寫的不是很好。網(wǎng)上也有相關(guān)的webresource的介紹。但發(fā)現(xiàn)很多都是目前最新版本不支持的。不知道是不是以前asp.net2.0早期版本。所以才進(jìn)行了簡單的修改。
以后在努力了。
新聞熱點(diǎn)
疑難解答
圖片精選