VS Team System 2005 ASP.NET unit test error.

If you get this error message when running an ASP.NET unit test in VS Team System 2005:

The web request 'http://localhost:19298/' completed successfully without running the test. This can occur when configuring the web application for testing fails (an ASP.NET server error occurs when processing the request), or when no ASP.NET page is executed (the URL may point to an HTML page, a web service, or a directory listing). Running tests in ASP.NET requires the URL to resolve to an ASP.NET page and for the page to execute properly up to the Load event. The response from the request is stored in the file 'WebRequestResponse_lnkGetMoreWork_Click.html' with the test results; typically this file can be opened with a web browser to view its contents.

Remove these lines/attributes from the unit test method declaration:

HostType("ASP.NET"), _
AspNetDevelopmentServerHost("%PathToWebRoot%", "/"), _
UrlToTest("http://localhost/")> _

ASP.NET 2.0 DataList - properties set in ItemDataBound event not persisted during postback

If you have a DataList control and capture the ItemDataBound event like this:

Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound

And then suddenly have the urge to do something to e.item and expect it to exist after a postback you best be a suppressing that urge because nothing you do to e.item in the ItemDataBound event of a DataList control will survive a postback. The reason used to be described here:

VS 2005 ASP.NET 2.0 DropDownList ToolTip in IE7

You can set the title attribute on the drop down list items to have ToolTip popups on your DropDownList items. This does not work in IE6 but works in IE7. For example you can do it right in the aspx like this:

<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem title="Choice 1 ToolTip" Value="1">Choice 1asp:ListItem>
            <asp:ListItem title="Choice 2 ToolTip" Value="2">Choice 2asp:ListItem>

Visual Studio will say that “Attribute 'title' is not a valid attribute of element 'ListItem'.” but it will run fine.
Or you can do it in the code behind like this:

Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.DataBound
Dim toolTip As String = string.Empty
For Each item As ListItem In DropDownList1.Items
toolTip = GetToolTips.(Integer.Parse(item.Value))
item.Attributes.Add("title", toolTip)
End Sub

Where GetToolTips is a custom function to retrieve tooltip text based on the passed in value.

ASP.NET 2.0 Data Binding Tips - How to avoid Eval()

Here is an excellent tip to speed up ASP.NET 2.0 Data Binding by avoiding reflection overhead:


If you're in a VB project then you have to use CType to cast Container.DataItem like this:

<asp:Label ID="Label3" runat="server" Text='<%# CType(Container.DataItem, ConfigurationSection).SectionInformation.SectionName %>'></asp:Label>

Another benefit of doing this early binding, if you're using VS 2005, is you get intellisense popup to aid in selecting the right property.

Accessing a property on the MasterPage in ASP.NET 2.0

To access a property on the masterpage in ASP.NET 2.0 you have to cast it like this:

For a Web Application project

CType(MyBase.Master, WebApplication1.Site1)

Or for a website project

CType(MyBase.Master, MasterPage)

Or you can specify the MasterType in the aspx like this:

For a Web Application project

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master"
    Inherits="WebApplication1._Default" %>
<%@ MasterType TypeName="WebApplication1.Site1" %>

Or for a website project

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    Inherits="Default" title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>

Which will then create a shadow property on Master that does the casting for you so in the code behind you can just use: