Solved – ToolboxBitmap problem

Another small but  hard problem of that adding toolboxbitmap to your custom control.endlich it solved.

instructions: create a new class library project, name it ClassLibrary1. 

 Add a bitmap to your solution and name it “MyButton.bmp” (should be 16×16).Name must be same as your class name.  Click the bitmap in the Solution Explorer and change the Build Action to “Embedded Resource”.
!!! Do not add image directly in Resouce.resx file designer or resource folder.I tried it doesnt work.

Write your control class code like this:

using System;
using System.Drawing;
using System.Windows.Forms;

internal class resfinder { }

namespace MyControls
      [ToolboxBitmap(typeof(resfinder), "ClassLibrary1.MyButton.bmp")]
      public class MyButton : Button


The “resfinder” class is a trick to let the GetImageFromResource() method find the bitmap resource in the proper namespace.  This is necessary because I made the namespace for the control (“MyControls”) different from the default namespace of the class library (“ClassLibrary1”).  The resfinder type reference forces .NET to look for the bitmap resource in “ClassLibrary1.MyButton.bmp” rather than “MyControls.ClassLibrary1.MyButton.bmp”.

Build the project.  Open the project that will use your control.  Right-click the tool box and select “Choose items…”.  Click on Browse and select the ClassLibrary1.dll assembly.  You should now see the MyButton control with the proper bitmap.

ASP.NET Get by ID Override ClientID

Some times we need to use html object’s id s  in javascript or in html source in Masterpage based ,including custom content   and user controls integrated complexed web know that the object IDs (ClientID) is generated by   .  When you are using Extjs or JSon kind of stuff its hard to manage and that generated ids because its long and complex.

An example of Extjs code that need to use id of Portal html object. generates an id like this
“ct100” is control id parent
“cphMiddle1” comming from ContentPlaceHolder id
“ModulePlace1” comming from userControl
“Portal1” object that i want to use its id.

if we sum of those the final id like this :

if you want to reach object you can find that id just in source code of builded aspx.
portal = Ext.getCmp(“ctl00_cphMiddle1_ModulePlace1_Portal1”);


You can use it for more easy by using like this:
portal = Ext.getCmp(“<%=Portal1.ClientID %>”);

There is another way to do it by overriding ClientID and UniqueID of your component.Instead of using base.ID use this.ID

        public override string ClientID
                return this.ID;
        public override string UniqueID
                return this.ID;

But one exception that should be cared about of id confilict.You should extra check for control ids that not conflict in other containers when overriding ClientIDs.


One tip : do not use orginal id text of ide created.Example like textboxes in your project can not be standart name of “Textbox1″,”Textbox2”,”Textbox3″… you should change “txtMyControlName”,”txtMyControlAge”,”txtMyControlSurname” or etc.


HttpHandler content-type as xml

        XmlNode xml = e.Xml;


        string strXml = xml.OuterXml;
        this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xml");
        this.Response.AddHeader("Content-Length", strXml.Length.ToString());
        this.Response.ContentType = "application/xml";