Date Format Recognition in ASP.NET Controls

To make an ASP.NET control validator recognize an alternate date format such as DD/MM/YYYY, set the culture at the page level with a command like this:

Page.Culture = “en-AU”;

This will set the validators for Australian English, and the following validator will work correctly:

1
2
3
<asp:CompareValidator ID="cvStartDate" runat="server" ControlToValidate="txtStartDate" 
ErrorMessage="The From Date should be in the format DD/MM/YYYY." Operator="DataTypeCheck"
Type="Date">*</asp:CompareValidator>

CSS and ASP.Net

We were recently handed some mock up ASPX pages to use in a facelift of an existing ASP.Net 2.0 application. The pages used CSS extensively and unfortunately used no server controls as in the existing application. The conversion has been painful and time consuming.

Apparently label controls that have no text play havoc with the format, large blank areas will appear when you narrow the browser window. I had to change them to be not visible and add code to switch the visible attribute on and off. This rendered useless my long time use of an informational label with view state disabled, which never needed clearing or making not visible.

Also some controls such as the checkbox are rendered with a SPAN around them that causes unwanted wrapping problems. I tried to have the created SPAN’s inherit a style, but this would not fix wrap problems no matter how wide I made the span width.

It is interesting to note that checkbox controls that are dynamically added to a panel do not have this problem. Of course then you have to maintain the view state of the control yourself which adds a lot of complexity.