Thursday, 29 January 2009

Free Java training courses

At http://www.sun.com/training/glassfish_login.html 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"
namespace="MyNamespace"
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.

Solution:
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.

Tuesday, 30 December 2008

JS error "Sys is not defined" caused by HttpModule

I have an ASP.NET application that makes use of Ajax Control Toolkit. Everything was working fine until I decided to implement authentication on application level using HttpModules. It's basically about authenticating each request to your application with one piece of code - before each request is processed the code defined in appropriate HttpModule is executed. You can read more on that here or here.

After I've configured my application to use the custom authentication HttpModule all controls from Ajax Control Toolkit (ACT) stopped working. Instead, I was getting JavaScript error "Sys is not defined". The cause of that was the authentication module, which was checking URL parameters to grant access to requested resources.

I've discovered that ACT was dynamically loading additional .resx files from the server. The dynamic requests (sort of Ajax calls) didn't contain appropriate parameters so they were rejected.

Solution:

I've added additional if clause to my authentication code that was allowing all requests to .axd files to pass, regardless parameters. I could do that since none of the files created by me was in that format and I didn't have to care about authentication when such files are requested. Of course, I'm open for suggestions how to resolve this in cleaner way.

Friday, 5 December 2008

How to get assembly file from GAC?

The .Net application I'm currently working on uses libraries from Global Assembly Cache (GAC). To see the libraries available in GAC just navigate to C:\windows\assembly with regular windows file explorer. The explorer will display the GAC content in a different way than regular files. You'll only see the list of available libraries. You can add assemblies to GAC by drag'n'drop:

Global Assembly CacheHowever, this view will only allow you to see the current GAC content and add/update libraries. This has some limitations e.g.:
  • It won't let you get the actual library file. Sometimes you may need to do that e.g. to backup file from GAC before you replace it.

  • You can't add files of different types e.g. PDB files. This could be useful if you'd like to see the line numbers in stack trace.

  • ...

You can bypass all those limitations by using different tool to access the folder content e.g. console or Total Commander. Note that the libraries placed in GAC are not saved directly in c:\windows\assembly folder. The dll-s you're looking for should be available at following path:
C:\windows\assembly\GAC_MSIL\Namespace.Project\
<assembly_version_number>__<assembly_public_token_key>\Namespace.Project.dll

Example
We're looking for library with name = Kainos.Framework.Web, version = 1.0.0.0 and PublicTokenKey = 1111aaaa1111aaaa. You can find it at:
C:\windows\assembly\GAC_MSIL\Kainos.Framework.Core\
1.0.0.0__1111aaaa1111aaaa\Kainos.Framework.Core.dll
Once you access the folder you can copy the assembly files, add pdb files, etc.

Thursday, 20 November 2008

IIS Error: "Unexpected Error 0x8ffe2740 Occurred"

When I try to start IIS the following error message is displayed:
"Unexpected Error 0x8ffe2740 Occurred"

Solution:
This happens because some required ports are not available. The most common application using required ports is Skype. You can conigure Skype to not use these ports:

  1. Open Skype

  2. Choose Tools > Options > Advanced > Connections

  3. Uncheck Use Port 80 and 443 as alternatives for incoming connections.

  4. Restart Skype

  5. Start IIS

Saturday, 1 November 2008

Error while exporting pages from SharePoint using SP Designer

While opening Sharepoint pages containing webparts using SP Designer I was getting the following error message:
"This page cannot be edited in Sharepoint Designer. You can edit the content in the browser, or edit the corresponding page layout in Sharepoint designer."



Solution:

  1. Open you Site Structure in SharePoint Designer

  2. Right click on your page and select “Detach from page layout”

  3. This will check the file out and right click again and select open > open with notepad

  4. This will display the content you need to export. You can save it to chosen location