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

Source: Internet
Author: User

Asp.net 2.0 Embedded resource solutions for custom control development Prerequisites : The following types of resources must be displayed in the properties page. , Set < Generation operation > Attribute , Set [ Embedded Resources ], :

  ► 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 icon file name is different from the Master Control name , Set the following before the class: .   [Toolboxbitmap (typeof (custombutton), @ "custombutton1.bmp")] Public class custombutton: compositecontrol, inamingcontainer { // ... .; }   Compile a project , Then 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 , Use the absolute path of the local machine as follows:   [Toolboxbitmap (@ "E: \ net \ custombutton ( Test Resources File) \ custombutton \ custombutton1.bmp ")] Compile a project , Then add this control in the toolbox to see the icon effect you just set. .   ► Custom Control embedding Javascript File Resources 1. Define metadata attributes [Assembly: webresource ("custombutton. custombutton_jscript.js ", "Application/JavaScript")] Namespace custombutton { // ... .; }   Where Webresource Parameter 1 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 embedding Image (GIF/jpg And so on ) 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;   ► Other related Custom ControlsArticle :   Http://blog.csdn.net/ChengKing/category/288694.aspx

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.