Thursday, 29 January 2009

Free Java training courses

At you can find 6 free 90-days trial courses on follwiong topics:

  1. GlassFish Application Server: Introduction (WMT-SAS-1536)

  2. Designing Java Web Services (WJ-4112-EE5)

  3. Adding Quality of Service and .NET Interoperability to Web Services (WMT-SAS-1543)

  4. Creating Reliable and Secure Interoperable Web Services (WMT-SAS-2544)

  5. Creating Transactional Web Services (WMT-SAS-2545)

  6. Working With the Web Services Policy (WMT-SAS-2546)

Sounds interesting to me - you better check that out before the promotion ends!

Thursday, 22 January 2009

DropDownList with OptGroup support

Strangely guys from Microsoft did not implement (forgot???) support for optgroup tag in their standard DropDownList asp control so it's not possible to group items on the list.

Most of the workarounds found in Web suggest use of Control Adapter, like this one. However, there are couple things I don't like in this solution:
  • Doesn't work correctly when DataSource, AutoPostBack or OnSelectedIndexChanged attributes are set
  • Overrides regular regular behaviour & rendering of DropDownList items
  • Works for all DropDownList controls on the page (cannot be switched off for some lists)

Instead, I propose to create our own custom control that extends the standard DropDownList class. We need to override the method RenderContents inherited by DropDownList from System.Web.UI.WebControls.ListControl. When overriding it is very useful to base on original implementation so the default behaviour is preserved. To get the original RenderContents method's code you can use .NET Reflector:

So, your custom list control needs to look as follows:
namespace MyNamespace
public class MyList : System.Web.UI.WebControls.DropDownList
protected override void RenderContents(
System.Web.UI.HtmlTextWriter writer)
// Custom implementation goes here
Once you create your custom DropDownList you can use it on a page just like any other control. You only need to register it explicitly using following directive:
<%@ Register assembly="MyAssembly"
tagprefix="ma" %>
<ma:MyList ... />

Advantages of this appraoch:
  • Original behaviour is preserved.
  • You can use custom control only if you need grouping without affecting the rest of drop-downs on page
  • You can implement several custom drop downs with different customizations
  • Should work with AutoPostBack & OnSelectedIndexChanged
I've found sample implementation using this approach here and here.

Saturday, 17 January 2009

Width of FileUpload control in Firefox

I'm using standard ASP.NET FileUpload control and had some troubles changing its width. For almost all browsers the regular width attribute does the job (as expected). However, for some strange reasons it is completely ignored by FF.

To change the width of FileUpload control in FF you have to use size attribute instead. Example:
<asp:FileUpload ... size="50" />
The units used by size attribute are characters. Remember to use both size (for FF) and width (for all other browsers) to make the change visible for all users. Sometimes it may be tricky to make this field have the same width on all browsers.

I'm not sure why Mozilla did it this way but I don't like it at all. Any Ideas?

I found solution here.