溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ASP.NET2.0 WebRource,開發(fā)微調(diào)按鈕控件的示例

發(fā)布時(shí)間:2021-01-30 10:08:23 來源:億速云 閱讀:171 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關(guān)ASP.NET2.0 WebRource,開發(fā)微調(diào)按鈕控件的示例的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

現(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 程序集最后修改的時(shí)間


webResource.axd只是ISAPI中的一個(gè)映射。你也可以在使用IhttpHandler。<add verb="GET" path="WebResource.axd"     type="System.Web.Handlers.AssemblyResourceLoader" /> webResource.axd是通過AssemblyResourceLoader類來自定義處理HTTP請(qǐng)求,根據(jù)所query傳遞的程序來識(shí)別從哪個(gè)程序集中獲取哪個(gè)資源。

下面以微調(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")]請(qǐng)注意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.(獲取對(duì)服務(wù)器端資源的 URL 引用)
我發(fā)現(xiàn)在早期版本當(dāng)中。它的使用方法是:this.page.GetWebResourceUrl

上面代碼是從指定的程序集中當(dāng)中獲取圖像名稱:Obies.Web.UI.WebControls.NumericTextBox_" + this.ImageSet.ToString() + "_BtnUp.gif,它返回的是一個(gè)服務(wù)器端資源的URL引用地址。類似于:
WebResource.axd?d=gWYJBlnQKynoTePlJ34jxyoSpR2Rh9lpYd8ZrSl0&t=632812333820000000

另外,MS提供一個(gè)Header類。Header類主要是對(duì)HTML頁面中的<Head runat="server"></head>的操作。包括Title等
呵呵。以后要修改一個(gè)頁面的標(biāo)題很很簡(jiǎn)單了。
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

感謝各位的閱讀!關(guān)于“ASP.NET2.0 WebRource,開發(fā)微調(diào)按鈕控件的示例”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI