Welcome to imar.spaanjaars.com

image
Welcome to the personal web site of Imar Spaanjaars where I write about software development with a focus on Microsoft web technologies
Image representing the Articles category

Watch Out When Setting the ID of a Master Page Dynamically

Published 15 years ago

It's not uncommon to set the ID of a Master Page in ASP.NET Programmatically. This is particularly useful when you have multiple master pages and want to have your CSS or JavaScript target specific control IDs in your code.

Without setting the ID property of the master page, a client side control ID may end up like this:

<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="Button" 
id="ctl00_ContentPlaceHolder1_Button1" /> 

The ctl00 prefix on the id and name attributes represent the auto generated ID of the master page. Even if your page uses a different master, you may end up with the same prefix. Setting the server side ID of the master programmatically allows you to control the full control ID, making IDs predictable and thus more useable in client side code. For example, the following code in the code behind of the master page:

protected void Page_Init(object sender, EventArgs e)
{
  this.ID = "Master1";
}
will result in the following HTML for the same button control:
<input type="submit" name="Master1$ContentPlaceHolder1$Button1" value="Button" 
id="Master1_ContentPlaceHolder1_Button1" /> 

This way you can assign a predictable master ID that your client side CSS and script can use.

If you use this trick, you have to be aware of when exactly to set the ID. Do it too late and you'll get in troubles.

Read on ...
Image representing the Blogs category

Wanted: Input for the Next Version of my N-Layer Architecture Articles!

Published 15 years ago

It's been more than one and a half year since I released the first version of my articles on N-Layer Design. Since then, the three articles combined have been read well over 200,000 times. Besides generating a lot of page views, the articles also attracted a lot of comments from you, my readers, with great feedback and requests.

Read on ...
Image representing the Blogs category

What Others Are Saying About Beginning ASP.NET 3.5 in C# And VB

Published 15 years ago

It's been more than six months since my latest book, Beginning ASP.NET 3.5 in C# And VB, has been released, so it's a good time to look back a little, see how the book has been received and what people think about it.

Read on ...
Image representing the Blogs category

Passed My MCPD Web Exams Today

Published 15 years ago

Today I passed the exam 70-528, part of the MCPD training.

Read on ...
Image representing the Articles category

Spaanjaars.Toolkit.ContentRating: Version 1.1

Published 15 years ago

Ever since I wrote the initial version of my ContentRating control back in 2006, I received a massive amount of feedback, both as comments below the article and as private e-mails. Not surprisingly, if you consider the article has been read over 19,000 times and has been rated 444 times (at the time of writing).

Besides getting a lot of "thank you's" from people who liked the control, I also got a lot of requests for a real-world example of a test site using the control. The test site that shipped with the control used fake data stored in ViewState to simulate a real backing store which obviously didn't cut it for a lot of people.

Also, a reader called vgt pointed out a bug in the control where an existing cookie would be overwritten by a new one one, effectively allowing you to vote for the previous item again.

Finally, I had a few requests of my own: I didn't like the default data source of 5 integers if you didn't supply a data source yourself. I also didn't like it that the control didn't raise an exception when you tried to data bind it without a valid data source.

So, enough reasons to fire up Visual Studio and get my hands dirty on some control fixing.

Read on ...
Image representing the Articles category

Fun With Extension Methods - Extending Object Part 1

Published 15 years ago

Some time ago I was showing a colleague how to enhance an object's Design Time capabilities (or actually Debug Time) by adding a DebuggerDisplayAttribute. I blogged about this attribute earlier, so I won't go into it again now. But what I do want to talk about is the way the attribute gets its data.

Read on ...
Image representing the Blogs category

Caching Best Practices

Published 15 years ago

Shortly after my ASP.NET 3.5 book was released in March 2008, I received feedback from Steven Smith who had reviewed the book. He pointed out that the code I am using to retrieve cached objects has a flaw. Fortunately, the problem is only likely to occur in high traffic sites, and is pretty easy to fix.

Read on ...
Image representing the Articles category

Fun With Extension Methods - Extending IDataRecord Part 2

Published 15 years ago

It's not uncommon that you have a method that accepts an object that implements the IDataRecord or IDataReader interface. It's also not uncommon that you cannot (fully) control the query that drives the IDataRecord. It could be the result of a SELECT * operation (bad idea) or it could be the results of a Stored Procedure for example. Especially in the latter case, it can be useful if you can check whether the IDataRecord contains a specific field. For example, you may want to check if the IDataRecord has a field called LastModified before you try to read and store this field in a local DateTime variable.

Unfortunately, the IDataRecord and IDataReader do not implement this behavior directly. However, it's easy to add with a simple extension method.

Read on ...
Image representing the Blogs category

Blogo.NET: A Real World Implementation of my N-Layer Architecture

Published 15 years ago

Ferdy Christant (also from the Netherlands) recently developed Blogo.NET, a blogging application built with .NET 3.5 and based on the architecture from my article series on N-Layer design.

Read on ...
Image representing the Blogs category

Sometimes the Error Message Says It All...

Published 16 years ago

Sometime ago I was working on a Web Application Project in Visual Studio 2008. The web site I was working on couldn't run against the built-in web development server, so I ran the application against IIS 7 on my Windows Vista machine (IMO, that's probably the best reason to upgrade to Windows Vista if you are a web developer: multiple web sites in IIS 7).

Life was good until I started debugging...

Read on ...

Mobile: False

Crawler: True

I: False