当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET2.0 WebRource,开发微调按钮控件

ASP.NET2.0 WebRource,开发微调按钮控件

2018年04月29日  | 移动技术网IT编程  | 我要评论

贵州163考试信息网,科密y68,网上购物网站大全

现在。有许多开发人员已经在使用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>目前我发现webresource.axd的参数跟现在版本有属不同。在早期文章介绍属性:
a 程序集名称
r 资源文件名称
t 程序集最后修改的时间
 


webresource.axd只是isapi中的一个映射。你也可以在使用ihttphandler。<add verb="get" path="webresource.axd"     type="system.web.handlers.assemblyresourceloader" /> webresource.axd是通过assemblyresourceloader类来自定义处理http请求,根据所query传递的程序来识别从哪个程序集中获取哪个资源。

下面以微调控件为示例。

使用步骤:
添加要嵌入的资源(比如图像)到项中
在资源管理器中,单击文件,在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源码当中。你需要使用下面代码来获取图像
    // 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.(获取对服务器端资源的 url 引用)
我发现在早期版本当中。它的使用方法是:this.page.getwebresourceurl

上面代码是从指定的程序集中当中获取图像名称:obies.web.ui.webcontrols.numerictextbox_" + this.imageset.tostring() + "_btnup.gif,它返回的是一个服务器端资源的url引用地址。类似于:
webresource.axd?d=gwyjblnqkynoteplj34jxyospr2rh9lpyd8zrsl0&t=632812333820000000

另外,ms提供一个header类。header类主要是对html页面中的<head runat="server"></head>的操作。包括title等
呵呵。以后要修改一个页面的标题很很简单了。
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);

        }      
下面是微调控件的截图

使用方法:
<%@ 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>

来源地址:
dnvs05/html/webresource.asp
由于原来的代码有点问题,很多特性都是最新vs2005不支持的。所以进行了修改。
源码下载:

在写这篇文章查了很多资料。也尝试用心去写。但总感觉写的不是很好。网上也有相关的webresource的介绍。但发现很多都是目前最新版本不支持的。不知道是不是以前asp.net2.0早期版本。所以才进行了简单的修改。
以后在努力了。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网