Peppy Custom Panel Control

This post is also dedicated to my companies prestigious client.

My team was facing a very peculiar problem with this peppy custom panel container control which one of my team member created from Control class (i.e. System.Web.UI.Control) instead of Panel class (i.e. System.Web.UI.WebControls.Panel).
The reason for choice was that the default markup generated by the Panel class was in the form of tables and since my client deals in Mobile Web portal and the browsers of devices are very very harsh on developers. You make a small mistake or a small smarteness will cost you a hard kick on your butt…i could use words which are even worse to tell you how sensitive these mobile browsers are 🙂  So, i need the markup in the form of “DIVS” instead of “TABLES”.

So, in order to generate the markup in the form of DIVS my friend created it using the Control class and Overrided the CreateChildControl method in it and finally, injected the necessary DIV to create a parent control with some attributes in the form of CSS classes passed by the consumer page or user control using this controls property holding the attributes in the form of NameValue pair.

After this thoughtfull yet messy code(i am sure this friend of mine will definately kill me after reading this article 🙂 ) it almost worked fine in every situation and just then it showed up with some bright colors almost at the verge of development cycle in other words, it broke into millions of pieces. 🙁

So the pseudocode goes like this:
==================================
public NameValuePair[] CustomAttributes
{
 //Contains the attributes passed by the consumer page/user control
}
 
protected override CreateChildControl()
{
 //Created the required div over here
 
 //looped through the CustomAttributes and added to the div above
 // looped through "this.Controls" collection 
 //and added each control to the div above(This is the real mess) 
}

 The above control works fine as long as this parent control contains static controls like: (Label, textboxes etc.). The control struggles when a control like CheckBoxList is placed under its hood. Obviously now the user will try to gather the selected checkboxes values and just then the control breaks. On PostBack when the page tries to gather the checkbox values by looping through this.items (i.e. ListItems) the count of ListItems comes out to be 0 (yes, ZERO).

Oops, forgot to tell you the CheckBoxList is also a custom control derived from Asp.Net CheckBoxList. This control was also overriden to get the markup in the form of DIVS. So, this.Items in last para will give you the ListItems of checkboxlist.

So, in a nut shell these are a kind of custom adapters written for adaptive rendering of the controls depending on the device type.

 Coming back to the point, I can’t tell you the exact reason for this count zero, I think we had to do something related to the viewstate while adding the individual control to the parent DIV in the CreateChildControl method.

Alright enough of problem statement, now lets come straight to the solution, After a lot of ignorance today i took up the task of clearing this mess. Poor this Custom Panel here i come yoooo man 🙂 hahaha

Here comes the magic code….

namespace custom.ServerControls
{
    [ParseChildren(false),
      ToolboxData("<{0}:CustomPanel runat=\"server\"></{0}:CustomPanel>")]
    public class CustomPanel : Panel
    {          
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.WriteLine("<div style=\"border:5px solid black;\">");
             //Its safe to write your custom code here
             writer.WriteLine(”<img src=”"your icon image source”" />”)
   
            //Calling base class(i.e. System.Web.UI.WebControls.Panel)
            //RenderContents method
            base.RenderContents(writer);
            writer.WriteLine("</div>");
        }
    }
}

There is the main part of the code! We simply override the RenderContents method! What this does instead of jumping ahead and just inputing the panel controls into the panel control, we instead snatch it before it finishes and add some of our own custom code!

It’s a simple htmltextwriter object so it’s really easy to use.

You take writer and use the writeline method to add the begining code. Don’t worry this won’t edit the contents of writer. I know it seems odd a little but writeline doesn’t effect the htmltextwriter at all, it just injects code into the page where the panel control is at.

So by this solution two of most significant problems are solved:

  1. My friend don’t have to create the custom panel from Control class as done above,
  2. The view state issue of the child controls will be handled by the panel class along with the EnableViewState = “true” property of the page,
  3. Since Control class does not provide Attributes propert for adding custom attributes to the panel like: CSS class etc. for which my friend has created the NameValuePair array property in the pseudocode above. As the current control is derived directly from Panel class the Attributes property will be available directly.  🙂

Cheers !!! Enjoy!!! 🙂

kick it on DotNetKicks.com

Shout it

pimp it

Dealing with Multiple Outlook profiles

Recently I was on client site of one of my companies prestigious client for the gathering of some new business requirement and understanding of their existing work model. I faced a typical yet very common problem which i think most of you have faced on your clientele’ visit.

Dealing with multiple outlook profiles specially when you are for a long term client site visit and had to juggle between your company mail account and a new mail id provided by your client to interact with their technical/Business team.

So, here is one common solution which i think most of you might be aware but this blog entry is for those who are still uaware of it. 🙂

The answer is “Extra Outlook”

Steps to configure:

1. Download Extra Outlook from http://www.hammerofgod.com/download/ExtraOutlook.zip,
2. Create a new profile in outlook. Control Panel -> Mail -> Add,
3. Create a bat file with the entry,
extraoutlook.exe “C:\Program Files\Microsoft Office\Office12\outlook.exe” /profile “New Profile”
4. Save the file with extension “.bat”,
5. Open the first instance normally by the outlook icon provided in the start menu,
6. Open second instance by running the bat file from command prompt or by double click.

Note:

1. Keep the bat file in same folder where the extraoutlook.exe is kept,
2. Provide the outlook.exe path as per your machine installation.

Worldkit:Open Source Awesome looking Mapping application

Problem
Are you looking for a good mapping application component to use in your application. It should have good graphics and should be easy to use??

Or

you want to display your data on a World or a local map. Just like Google maps or Live Maps but free of cost??

Solution
The solution to the above problem exists with the name of Worldkit
worldKit is an easy to use and flexible mapping application for the Web. Light weight GIS. It’s a SWF based app, configured by XML, data fed by RSS. Stand-alone use or integration in larger projects.

Some of the Features of Worldkit

  • Ubiquitous use in the Flash Player and with RSS feeds.
  • Highly configurable look and feel. Can use images for marking annotations.
  • Integrates with weblogging tools, and any software producing RSS.
  • Displays photos within the map.
  • Zoom & Pan. Integrates with Zoomify for high resolution images, and WMS Sources.
  • Lines and Polygons. Time Navigation.
  • Accepts input for Collaborative Cartography & GeoWiki.
  • Annotations are categorizable. Javascript interface for GIS layer functionality.
  • GPS track routes.

Basically its a flash application which can take data from RSS feeds directly or from an XML file as specified by us.
It also shows the night and day lights on the same image.

It has got a specified configuration format.

Snapshot
worldkitsample

Examples
The tool has already been used at many sites around the web and the complete list can be found on Examples page.

kick it on DotNetKicks.com

Shout it

pimp it