Yearly Archives

53 Articles

Posted by Ronald Anthonissen on

Dust-Me Selectors Version 2.0

After many months of toiling in our secret underground laboratories, Dust-Me Selectors Version 2.0 is finally here!
If you’re one of the many people who made suggestions or commented on the original version, you’ll be pleased to know that the new version incorporates everything you asked for and more.
It was quite a challenge to bring all this together, particularly since Mozilla’s documentation is so … er … erratic (in fact for some functionality I had to look in Firefox’s source code just to figure out how it’s done!) But there’s nothing like a challenge to exercise the mind, and I think you’ll agree that the final result is well worth the gritty struggle.

SitePoint Blogs Dust-Me Selectors Version 2.0

Posted by Ronald Anthonissen on

How To Create A Custom Control

  1. Create a new ASP.NET Web Application, Windows Forms Control Library or Class Library project
  2. Create a new class and inherit from System.Web.UI.WebControls.WebControl or from a specific control (like TextBox)
  3. Override the Render method and call writer.write() to write raw HTML to the page. ASP.Net server tags won’t work
  4. Use WriteBeginTag(), WriteEndTag(), RenderBeginTag(), RenderEndTag(), AddAttribute(), AddStyleAttribute() and WriteAttribute() to create HTML tags and attributes
  5. Add design-time attributes to properties, like:
    [Description(“The text to be shown in the control”)]
  6. Define a tagprefix attribute:
    [assembly: System.Web.UI.TagPrefix(“Anthoro.WebControls”, “awc”)]
    namespace Anthoro.WebControls
    { …
  7. Add a toolbox icon:
    1. Create a 16×16 pixel bitmap (BMP 16 colors) with the same name as the control.
    2. Add it to the root of your project
    3. Set its Build Action to “Embedded Resource”
  8. Add additional resources (stylesheet, images, text files, …) and mark them as “Embedded Resource” also
  9. Add an Assembly attribute for each resource to your AssemblyInfo.cs:
    [assembly: WebResource(“”, “text/css”, PerformSubstitution = true)]
    When the PerformSubstitution parameter is set to true, the resource will be processed and other webresource URL’s inside it will be parsed and replaced (works only for text-based resources:
    background-image: url(‘<%= WebResource("Anthoro.Controls.back.png")%>‘);
  10. Pay attention to the full namespace and folder structure where your resources are stored. The resource name is build as: Namespace + Subfolders + filename
  11. At design-time, the control is displayed by running the rendering logic. To override this, use the GetDesignTimeHtml(), GetEmptyDesignTimeHtml() and GetErrorDesignTimeHtml() methods

Update: Unlike in C#, in VB.Net the subfolders are not taken into account with the namespace. So the example above in point 10 will be: Namespace + filename