HealthVault applications using Visual Basic .NET

When starting a new HealthVault project using Visual Basic .NET, the initial project created by Visual Studio needs some modification to work correctly. This post details the changes required to make it work successfully. To create a HealthVault Project, you need to start with a website project – this How-To guide explains how to get started.

When building website projects with Visual Basic, Visual Studio adds the following @ Page Directive to your WebForms:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="redirect.aspx.vb" Inherits="redirect" %>

Notice that the AutoEventWireup property is set to False by default. You can read more about this attribute on MSDN. Visual Studio does this for VB primarily because VB has the Handles keyword, and the IDE adds this keyword for you when you select the page events from the event drop-down controls in the code window. So a typical Page_Load event would look like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

If you remove “Handles Me.Load” from this method, the event will not get fired. However, if you set the AutoEventWireup property to True, the event will get fired – because the framework now depends on the method signature, and not the Handles keyword (so the signature becomes important).

In the HealthVault SDK, the Page class does not wire-up the events – it relies on the framework to do that. Because this property is set to False, you’ll see that your pages are not getting redirected after authentication has succeeded. To fix this issue, simply set the value of this attribute to True.

Note that you don’t need the Handles portion in your Page events after you set this value to true. So the following method can become your Page load event

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub

However, this only applies for your Page events, not other events. For example, for a button (Button1) on the form, you will still need the handles keyword as follows:

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) _

Handles Button1.Click

End Sub

Please post your questions, concerns, or comments. Thank you.