Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...

Sunday, May 29

Personalization [Web Parts] in ASP.NET 2.0

After my experiments with Master Pages in Visual Studio 2005, it was time to do some tricks with Web Parts.

You can think of Web Parts as modular Web page blocks. Each block can be added or removed from the Web page dynamically, at runtime (see my previous post about the personalized Web Parts in the Google homepage). Code for organizing and manipulating Web Parts is built into ASP.NET 2.0. All of the functionality for adding, removing, and configuring layout is automatically handled by the Web Parts system. The programmer simply builds Web Parts and assigns them to Web Part Zones. A user can mix and match Web Parts, display them in any order, and expect the configuration to be saved between site visits. All the functionality of Web Parts, including adding, removing, and listing, is managed automatically using a WebPartManager.

The personalization provider creates the link between the Web Parts feature that consumes personalization data, and the data store that contains the user information. You can configure a personalization provider and connect it to a certain database. The personalization provider supports the persistence of Web Part configurations and layouts for each user.

In Beta 1, ASP.NET application services (like personalization) include a Access data provider, and use them by default. In Beta 2, however, this functionality is replaced by support for SQL Server 2005 Express Edition, the new version of SQL Server which combines the file-based simplicity of Access databases with seamless deployment. The developer model of using the application services stays exactly the same, but the backend implementation will now be much more robust and performant.

On my machine, I installed a Virtual PC [Windows Server 2003] with this configuration :
  • Visual Studio 2005 Beta 2 (Standard Edition)
  • SQL Server 2005 April CTP
When I created and ran my first Web Part application, I immediately got an error.

What happened? Well, the webpage (containing some Web Part stuff) was fired in the browser and tried to make a connection to the data store with the default Personalization Provider [SQL Server Express] to store/retrieve the user-settings. Because on my machine there's no SQL Server Express installed, an exception was thrown. I did not want to make use of SQL Server Express. Instead I wanted to use the installed database on my machine to store personalization settings. To fix this I had to do two things ...
  1. Configure SQL Server to store information for ASP.NET application services

    ASP.NET includes a utility for installing the SQL Server database used by the SQL Server providers called aspnet_regsql.exe. The aspnet_regsql.exe tool is located in the "\WINDOWS\Microsoft.NET\Framework\2.0" folder on your Web server. This executable will bring you to a wizard that creates the aspnetdb database. Read more here.

  2. Change configuration of machine.config

    By default (beta 2), the default provider is still SQL Server Express. ASP.NET 2.0 provides a SQL Server-based provider named AspNetSqlProvider. Providers are registered in the section of the configuration file under the main node .

    The connectionStringName attribute defines the information needed to set up a connection with the underlying database engine of choice. LocalSqlServer is the name of an entry in the section of the configuration file. That entry will contain the appropriate information to connect to the desired database.

    I've commented out the old connectionString (SQL Server Express) and replaced it by a connection to the CTP-edition of SQL Server 2005.
Note that you can set some administration/configuration settings via the built-in tool : the ASP.NET Web Site Administration Tool. It has a wizard-like interface and you can invoke by selecting ASP.NET Configuration from the Website menu in Visual Studio 2005. You can easily set up roles, users and access permissions for your site. It lets you also configure the data store for storing membership/personalization data.

At the end, my Web Part page loaded just fine! It was all about configuration. Read more on personalization in ASP.NET 2.0.

Thursday, May 26

Personalize your Google Homepage

See information you care about on your Google homepage :

Before sign in ...

After sign in : choose settings ...

After saving preferences ...

Note that this technology is still in development (beta). You can also drag and drop the different items [Web Parts] at different locations in your page.

Thx for pointing me to this link Kim! I love this kind of all-in-one functionality because it saves me time. I hope that the future brings even more personalization : local information/news, custom rss-feeds, ...

I still wonder what "ig" means in the google-url... Please help me get some sleep!

Subscribe to Executive Microsoft E-Mail

Last week I've got mail from Bill Gates! ;-)

Subscribe to executive e-mail from Bill Gates, Steve Ballmer and other Microsoft executives. Subscription also possible with RSS ...

Mail of Bill Gates on May 19, 2005 : The New World of Work.

Some interesting paragraphs about the way we will work in the (near) future ...

Improving personal productivity: One consequence of an "always-on" environment is the challenge of prioritizing, focusing and working without interruption. Today's software can handle some of this, but hardly at a level that matches the judgment and awareness of a human being. That will change -- new software will learn from the way you work, understand your needs, and help you set priorities.

Unified communication: Integrated communication will provide a single "point of entry" to the networked world that is consistent across applications and devices. People should have a unified, complete view of their communication options, whether by voice or text, real-time or offline, with ready access to tools like speech-to-text and machine translation. You should be able to listen to your email, or read your voicemail. Project notifications, meetings, business applications, contacts and schedules should be accessible within a single consistent view, whether you're at your desk, down the hall, on the road or working at home.

Team collaboration: Over the next decade, shared workspaces will become far more robust, with richer tools to automate workflow and connect all the people, data and resources it takes to get things done. They will capture live data and documents in ways that will benefit teams that work across the hall or around the globe. Meetings will be recorded with sophisticated cameras that can detect and focus on speakers around the room. Notes taken on a whiteboard will automatically be captured and emailed to participants, and attached to the video of the meeting. They will also serve as lasting repositories for institutional knowledge, so teams won't have to "reinvent the wheel" and work with limited knowledge of the company's past experience.

About Team collaboration : hopefully Visual Studio 2005 Team System won't be far from this ideology ...

Friday, May 20

into XSLT

The last two weeks I've been working intensively with XSLT (Extensible Stylesheet Language Transformation) to transform (serialized) XML documents into other XML documents. It was about time to refresh/update my knowledge about all this XML-related stuff! I knew what XSLT basically could do, but I really didn't have a lot of XSLT-syntax in my fingers ...
  • XML
    XML (Extensible Markup Language) is a standard for creating markup languages which describe the structure of data
  • XSL - XSLT
    XSLT (Extensible Stylesheet Language Transformation) is kind of an extension for XSL. XSL (Extentsible Stylesheet Language) specifies the styling (separating style from content) of an XML document by using XSLT to describe how the document is transformed into another document that uses the formatting vocabulary. First there was XSL, which was conceived as a language to do styling (how an XML document should be rendered). Then XSLT was carved out as a separate sub-language to do the first part of styling, which is transformation.
  • XPath
    XPath is a (query) language that describes how to locate specific elements (and attributes, processing instructions, etc.) in a document. It allows you to locate specific content within a XML document. XPath treats a XML document as a logical ordered tree. XPath information is processed using XSLT.
XML is nowadays widely used as a data interchange syntax and therefore the need for applications to convert data from one XML document to another format has increased a lot. XSLT is designed for doing these kind of transformations. It looks to me that an XSLT stylesheet for transforming XML can be made much more resilient to changes in the details of the XML documents than a programming language using the low-level Document Object Model interface [building XmlDocument in C# from scratch]. Changing an XSLT stylesheet is also much faster than recompiling and redeploying your entire application.

Unfortunately, the power and associated complexity of XSLT can be overwhelming at the beginning, preventing many from experimenting with it. I've learnt a lot from other examples (tutorials) and from best practices a colleague gave me. I also recommend using XMLSpy as editor for dealing with XML-related documents. The XMLSpy XSLT Debugger makes it easy to troubleshoot (step-by-step) and fix XSLT stylesheets. At the same time you have a clear view of the original XML, the xslt stylesheet in debug mode and the output as it is being generated in real-time.

Any ideas about performance of XSLT-tranformations? I should give this a closer look next week ...

Wednesday, May 18

error : identifier 'xxx' out of scope

Ever been in the situation where the Command Window or ToolTip doesn't "function" properly while debugging (Visual Studio 2003)? Yip, quite annoying ... but it makes sense! See the example below ...

Why can't I get the counterString-value? I'm NOT out of scope!?


Check the build configuration properties of your project and make sure that the "Optimize Code" property for Debug is set to false! After that "correction" you will see that the variable will return its value ...


When the compiler optimizes code, it repositions and reorganizes instructions, resulting in more efficient compiled code. Because of this rearrangement, the debugger cannot always identify the source code that corresponds to a set of instructions. For this reason, you should do your debugging using an unoptimized version of your program if at all possible.

Below you find two screenshots of the disassembled code (Reflector) : the first one with the "Optimized" option set to false and the second one with the "Optimized" option set to true.

In the optimized version you can verify that there's no variable that contains the counterString. As a matter of fact, it's normal/logical because that variable is never used in its scope ... but in certain circumstances (not in my example) these variables can contain valuable (temporarily) information while debugging! Make sure to set the "Optimize Code" property to false when you want to deal with those kind of things. The default setting is false for Debug and true for Release. No bug in Visual Studio after all, but you have to know it ;-)

Tuesday, May 10

Change Master Pages (VS 2005) at run-time

Master Pages are one of the hottest new features of ASP.NET 2.0. You will love it! Developers can now create a website in which various physical pages share a common look and feel. The master page will contain ContentPlaceholders for content that the derived pages will provide. All common information is shared in a single master page. At design-time you can visually see how your aspx-page will eventually look like and you are only able to edit the ContentPlaceHolder-regions.

In my example I've used a master page to create a website that will support navigation for multiple languages (English - French - Dutch). It's not a typical example for using master pages, but it shows you how you can change your master page at run-time and support for multiple languages is almost always required for Belgian websites. Belgium has three official languages : French, Dutch and German ... but English is most of the time used for general communication in the bigger companies. English has become the "working" language in Belgium. Yip, strange behavior for a country with a population of only 10 million people!

The website contains only 1 aspx-page (Default.aspx) that is based on 1 master page (MyMasterPage.master). At the end, the page will be able to display content in English, French and Dutch and will disable the hyperlink for the current language.

The master page contains three "Hyperlink"-controls and a body-ContentPlaceHolder. All three links refer to the same aspx-page with a different Querystring.

The aspx-page is linked to the MyMasterPage and a heading 2 is entered into the ContentPlaceHolder-block.

The CodeFile for the master page contains a public method for disabling a hyperlink according to the language-parameter.

In the Page_Load method in the CodeFile for the aspx-page, the language is set (default = English), the "DisableLink" method is called and the Title + Header is properly set.

This is only a very simple example of how you can alter a master page at run-time, but it's very powerfull because it lets you change each server-control that's created in your master page. You can also work with properties on your master page instead of with public methods.

Monday, May 9

VS2005 : from beta 1 to beta 2

The last couple of days I've been converting a beta 1 project (ASP.NET) into beta 2 (Visual Studio 2005 Standard Edition). There is no upgrade wizard included in the beta 2 edition, so you have to deal manually with the compile-errors you will encounter.

Here are some compile-errors I had to solve to be able to compile my solution again :
  • The CompileWith/ClassName attributes in the compilation model are no longer supported. The compilation model has changed in beta 2 with the new CodeFile/Inherits attributes providing a model that is similar to v1.x

    The compilation model for ASP.NET 2.0 has changed (breaking change from Beta 1) in Beta 2. It will require you to make small changes to any application built using ASP.NET 2.0 Beta 1. The "compileWith" @Page attribute in beta 1 specified the name of the referenced code-beside file to use. This attribute no longer exists in beta 2 and is now replaced by the "CodeFile" attribute. The ASP.NET Runtime for Visual Studio 2005 still supports codebehind so v1.x web applications can be moved unchanged to Visual Studio 2005 (beta 2). The "ClassName" to "Inherits" change is required.

  • 'ASP.xxx_master.FrameworkInitialize()': no suitable method found to override.

    This error pops up when compiling my aspx-pages and my masterPages. The code-separation model in Visual Studio 2005 creates 2 classes, even though the code-separation file is defined as a partial class. The "Inherits" class defines a base class and this class is now (beta 2) required to derive from System.Web.UI.Page or System.Web.UI.UserControl for user controls or System.Web.UI.MasterPage for master pages or child class of one of these classes.

  • 'xxx_master.yyy(object, System.EventArgs)' is inaccessible due to its protection level.

    You must make your private methods (beta 1) 'protected' or 'public' (beta 2) in your code-behind files, so they can be properly accessed in your web-pages.

  • Some compilation errors are due to changes to the special directory structure in beta 2. The "Code" directory for example must be renamed to "app_code". Classes that were previously declared in the "Code"-directory must be created now into the "app_code"-directory. More info about these directory naming changes at