Several embedded resource solutions related to Asp.net custom control development

Source: Internet
Author: User

Prerequisites: You must set the <generate operation> attribute to [embedded resource] In the properties page of each of the following types of resources to be introduced:

:

►Solutions for adding custom icons to custom controls

Method 1:
Add an icon file in *. BMP format in the custom control project and name it
Same as the main control file, the extension is. bmp. For example, the main control file name is:
Custombutton. CS, the icon file is named custombutton.bmp. compile the project.
Then add this control in the toolbox to see the icon effect you just set.

Method 2:
The name of the icon file is different from the name of the main control. Set the name as follows before the class.

[Toolboxbitmap (typeof (custombutton), @ "custombutton1.bmp")]
Public class custombutton: compositecontrol, inamingcontainer
{
//....;
}

Compile the project, and add this control in the toolbox to see the icon effect you just set.

Method 3:
The icon file name is different from the Master Control name, and the local absolute path is used as follows:

[Toolboxbitmap (@ "E: \ net \ custombutton (test Resource
File) \ custombutton \ custombutton1.bmp ")]

Compile the project, and add this control in the toolbox to see the icon effect you just set.


►Custom controls embed Javascript file resources

1. define metadata attributes
[Assembly: webresource ("custombutton. custombutton_jscript.js ",
"Application/JavaScript")]
Namespace custombutton
{
//....;
}

Here, parameter 1 of webresource is: Control namespace +. + JS script file name

2. Use

If (! Page. clientscript. isclientscriptincluderegistered
("Myjavascript "))
{
Page. clientscript. registerclientscriptinclude
("Myjavascript", page. clientscript. getwebresourceurl
(This. GetType (), "custombutton. custombutton _ JScript. js "));
}

►Custom control embedded image (GIF/jpg) file resources

1. define metadata attributes

[Assembly: webresource ("custombutton.nopic.gif", "image/GIF")]
Namespace custombutton
{
//....;
}

2. Use

string strimagesrc = page. clientscript. getwebresourceurl
(this. getType (), "custombutton.nopic.gif");
system. web. UI. webcontrols. image IMG = new
system. web. UI. webcontrols. image ();
IMG. imageurl = strimagesrc;

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.