Posts
288
Comments
25
Trackbacks
207
July 2006 Entries
Using Themes to get around CSS problems

Here's a little tip I've just discovered, although it's so simple I'm sure others must be using it. As we all know, IE6 isn't CSS 2 compliant; one feature not supported is the use of selectors. This stops us, for example, from this sort of thing:

input[type="text"] {border:1px solid #000;}

This would mean that only text entry input fields have a black border, while all other entry fields, such as check boxes, remain borderless. A simple way around this problem is to define CSS classes for the style you require and  use a theme to set the classes; within the theme you can place the following:

<asp:TextBox runat="server" CSSClass="txtBox"/>
<asp:Button runat="server" CssClass="button" />

Then set the default StyleSheetTheme in the config:

<pages StyleSheetTheme="Default" />

Now all textboxes have the set style and not all input fields. As this is a stylesheet theme it can also be overridden on the control itself.

I'd always considered themes for switching between UIs, but this allows you to use them to get around some browser issues.

posted @ Friday, July 21, 2006 1:43 PM | Feedback (1)
The Case of the Missing Error
In true Earl Stanley Gardner style, I need a hotshot lawyer and detective to help me find some missing error messages. Visual Studio 2005 assures me I have errors, but it doesn't know where they are:
posted @ Monday, July 17, 2006 4:43 PM | Feedback (4)
Conditional stylesheets in Themes

While themes in ASP.NET 2.0 are great, one of the problems is how to have conditional stylesheets for a theme, IE6/7 specific for example; by default ASP.NET loads all stylesheets held within a theme. I've just discovered a great way to do this and it's been out there for a while, but I bet not many people have seen it. I was looking at the ASP.NET Developer Centre Design Templates and downloaded the first one, the Commerce one, which has the greatest solution to the theme/css problem.

This solution has an expression builder in it, one for themes. Expression builders are used for dynamic expressions within pages and are what is used to set connection strings. Eg:

ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

Creating a theme expression builder allows us to do this:

<!-- IE7-specific fixes -->
<!--[if IE 7]>
<style type="text/css"> 
    @import url(<asp:Literal runat="server"
       Text="<%$ Themes:StylesheetTheme(~/Assets/CSS/{0}_ie7.css) %>" />); 
</style>
<![endif]-->

Which gives us the aspects of conditional stylesheets, but linked to the theme. This is a really sweet idea. I just wonder how much more hidden stuff there is in the other templates at the design centre.

posted @ Thursday, July 13, 2006 2:35 PM | Feedback (0)
ASP.NET 2.0 Web Menu Editor

I've been sitting on this project for a while in the vain hope I'd get some time to make it better and loo nicer, but I know that's not ging to happen soon. So, I'm releasing into the wild an ASP.NET 2.0 Web Menu Editor - a Windows Form application that allows editing of SiteMap files. It's fairly simple, with a TreeView to provide the node handling and supports custom attributes and roles. It also supports create of template pages, based upon the SiteMap, using VB/C#, code-inline/code-behind and standard pages/master-content pages. There is plenty more to do, but it's useable and useful.

You can download the Visual Studio 2005 project here.

posted @ Saturday, July 08, 2006 6:17 PM | Feedback (3)
App_Offline more useful than I thought
Another one that came up last week while training. I was explaining the App_Offline file and how it can take the application offline, when someone asked "can it redirect". I'd never thought of this, just never had had the need, but yes it case. Just put a meta refresh tag in (it's an HTML page after all) and the offline file will be displayed, then redirect to your target. Useful if you have a backup site.
posted @ Wednesday, July 05, 2006 2:53 PM | Feedback (1)
Page.Master and Master are not the same
This hit me during a training course last week; we've become used to properties of and ASP.NET page being accessed either directly by the property name or preceded with Page.. When using strongly typed master pages though, the two ways of accessing the Master property aren't the same. For example, assume I have a master page with a public property:
public string TitleText
{
get { return TitleLabel.Text; }
set { TitleLabel.Text = value; }
}
In my content page I have: 
 <%@ MasterType TypeName="MasterPage" %@gt;

In the content page code, the following works:
 Master.TitleText = "whatever";

While the following doesn't:
 Page.Master.TitleText = "whatever";

You don't even get IntelliSense in the latter case and it fails to compile. The reason is the way Page is cast as the strongly typed master page.
posted @ Wednesday, July 05, 2006 2:49 PM | Feedback (1)