asp.net2.0 Webrource, developing the Spinner button control

Source: Internet
Author: User
Right now. There are many developers who are already using Asp.net2.0 's webresource functionality. WebResource allows us to embed resources into assemblies. including images, text, and so on.

In introducing WebResource we have to introduce WebResource.axd, let's see

Script language= "javascript" src= "webresource.axd?a=s&r=webuivalidation.js&t=631944362841472848" type= " Text/javascript "></script> Now I find that the WebResource.axd parameters are different from the current version. In earlier articles, the properties were described:
A assembly name
R Resource File name
T the last time the assembly was modified


WebResource.axd is only a mapping in the ISAPI. You can also use the IHttpHandler. <add verb= "GET" path= "WebResource.axd" type= "System.Web.Handlers.AssemblyResourceLoader"/> WebResource.axd is the process of handling HTTP requests through the Assemblyresourceloader class to identify which resource is fetched from which assembly according to the program passed by the query.

The following is an example of a micro-control piece.

Use steps:
To add a resource to be embedded (a comparison) to an item
in Explorer, click File, and in the property window, build Action select Embedded Resource (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 ")] Notice the webresourceattribute format:
[Assembly:webresourceattribute (" MyNameSpaces.Resources.MyImage.gif "," Image/gif ")]
in the control source. 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. (Gets the URL reference to the server-side resource)
I found in earlier versions. It is used in the following ways: 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 is primarily for Oh. It's very easy to change 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);
Previous version of the method? You can only use the following code to solve the
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);

}
The following are the micro-control parts

How to use:
<%@ register tagprefix= "CC" namespace= "Obies.Web.UI.WebControls" assembly= "Obies.Web.UI.WebControls"%>

<cc:numerictextbox width= "imageset=" Silver "length=" 2 "runat=" Server "id=" NumericTextBox1 "
Maxvalue= "Ten" minvalue= "0" ></cc:NumericTextBox>
<cc:numerictextbox width= "imageset=" Green "length=" 2 "runat=" Server "id=" NumericTextBox2 "
Maxvalue= "Ten" minvalue= "0" ></cc:NumericTextBox>

Source Address:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
Dnvs05/html/webresource.asp
Because the original code is a bit problematic, many features are not supported by the newest VS2005. So the changes were made.
SOURCE Download:http://www.cnblogs.com/Files/cnzc/PostWebFormBetweenFrames.zip

In writing this article looked up a lot of information. Also try to write with heart. But the overall feeling is not very good to write. There is also an introduction to the relevant webresource on the Internet. But many of them are not supported by the current version. I don't know if it was before asp.net2.0 earlier versions. So we made a simple modification.
After in the effort.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.