VS 2005 Team System VB.NET Unit Test Class and method name are case sensitive

I had changed the name of a class to match Code Analysis class name criteria that specifies what parts of a class name should be upper case/lower case.  I did a global search and replace.  Some time later I ran a unit test and got this error:

System.TypeLoadException: Could not load type

After a bit of research I discovered that even though the class I had changed casing on was a VB class the unit test class is case sensitive.

ASP.NET 2.0 Wizard Control - Cancelling the next/previous button

If your using the ASP.NET 2.0 Wizard control and you want to stop the next button from going to the next step you have to set the event arg property Cancel to true like so:

Private Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
e.Cancel = True
End Sub

ASP.NET 2.0 Stack Overflow error in Wizard control

Was using the MaintainScrollPositionOnPostback=true in a page directive with the ASP.Net 2.0 Wizard control and started getting a stack overflow error when clicking on a Sidebar button.  Could not find a decent fix so I opted for a workaround and removed the MaintainScrollPositionOnPostback attribute and implemented this:


ASP.NET 2.0 RegularExpessionValidator to exclude a specific line.

Say you had the following select:

<select id="ItemSelect" runat="server">
 <option selected="selected">Select your item</option>
 <option>Item one</option>
 <option>Item two</option>
 <option>Item three</option>

And you wanted to force the user to select Item one/two/three. You could do this by creating a RegularExpressionValidator to to accept anything but the “Select your item” option like so:

<asp:RegularExpressionValidator ID="ItemRegularExpressionValidator" runat="server" ControlToValidate="ItemSelect"
                                ErrorMessage="Item Required" Text="*" SetFocusOnError="true" ValidationExpression="^((?!Select your item).)*$"></asp:RegularExpressionValidator>

Copy contents of a windows popup dialog

Some windows dialog's allow you to highlight part of the text in the dialog and press ctrl-c to copy that text which is great. But some dialog's do not allow this for example this one:

I wanted to copy the the compile error but it won't let me. What you can do in this situation is just click on the dialog title bar to make sure it is selected and press ctrl-c. This copies the whole dialog and then just open Notepad and paste it in Notepad like this:

Then you can highlight the text you want and carry on.

Handling the SelectedIndexedChanged event of a DropDownList in a GridView in ASP.NET 2.0

Say you had a GridView with a dropdownlist like this:

<asp:GridView ID="testGridView" runat="server">
        <asp:BoundField DataField="TestField" />
                <asp:DropDownList ID="TestDropDownList" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="1">Item 1</asp:ListItem>
                    <asp:ListItem Value="2">Item 2</asp:ListItem>

And you set it’s datasource in the page load event like this:

Protected Sub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
    If Not Me.IsPostBack Then
        Dim testTable As New DataTable
        Dim testColumn As New DataColumn
        testColumn.ColumnName = "TestField"
        testColumn.DataType = GetType(String)
        Dim testRow As DataRow
        testRow = testTable.NewRow
        testRow.Item("TestField") = "Item 1"
        testRow = testTable.NewRow
        testRow.Item("TestField") = "Item 2"
        testRow = testTable.NewRow
        testRow.Item("TestField") = "Item 3"
        Me.testGridView.DataSource = testTable
    End If
End Sub

Now say you wanted to add an event handler of the drop down list in the GridView. You may be tempted to try using the AddHandler method in the RowDataBound event of the GridView like this:

Protected Sub testGridView_RowDataBound(ByVal sender AsObject, ByVal e As GridViewRowEventArgs) Handles testGridView.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim testDropDownList As DropDownList = CType(e.Row.FindControl("TestDropDownList"),             DropDownList)
        AddHandler testDropDownList.SelectedIndexChanged, AddressOf TestDropDownList_SelectedIndexChanged
    End If
End Sub

Protected Sub TestDropDownList_SelectedIndexChanged(ByVal sender AsObject, ByVal e As EventArgs)
    Dim bla As Integer = 3
End Sub

But you will unfortunately discover that this does not work as a break point set on Dim bla is never reached. You have to tie the event handler directly in the aspx like this:

<asp:DropDownListID="TestDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="TestDropDownList_SelectedIndexChanged">

Using VB.NET reflection to get a list of the current objects private fields

If you want to get a list of the current objects private fields you can do so like this:

me.GetType.GetFields(system.Reflection.BindingFlags.Instance or Reflection.BindingFlags.NonPublic)