Blog Archive

Search Blog

Blog List

Contact Me






Enter the code shown above in the box below
Send

 

Announcements

Recommended Websites

Events

Event StartEvent EndTitle

Recommended Reading

Most recent blog entries

Author: Darren McLeod Created: Wednesday, October 17, 2007 9:05 PM
This will contain tips and tricks I learn at work. Mostly about programming with Visual Studio 2005 Team System, ASP.NET 2.0, VB.NET.

Say you had a GridView with a dropdownlist like this:

asp:GridView ID="testGridView" runat="server">

Columns>

asp:BoundField DataField="TestField" />

asp:TemplateField>

ItemTemplate>

asp:DropDownList ID="TestDropDownList" runat="server" AutoPostBack="true">

asp:ListItem Value="1">Item 1asp:ListItem>

asp:ListItem Value="2">Item 2asp:ListItem>

asp:DropDownList>

ItemTemplate>

asp:TemplateField>

Columns>

asp:GridView>

 

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

ProtectedSub 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)

testTable.Columns.Add(testColumn)

Dim testRow As DataRow

testRow = testTable.NewRow

testRow.Item("TestField") = "Item...

Read More »

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)

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/")> _

 

...

Read More »

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 is described here:

 

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104649&wa=wsignin1.0

...

Read More »

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>

asp:DropDownList>

 

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)

Next

...

Read More »

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

http://www.dasblonde.net/CommentView,guid,edc5323f-2afa-4ae5-9513-fbfb380940d4.aspx

And if your in a VB project then of course you have to use CType to cast Container.DataItem like so:

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

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

...

Read More »

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" CodeBehind="Default.aspx.vb"

    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:

Me.Master

...

Read More »

Finally managed to get my DNN v4.6.2 install into the root, thanks to http://www.bahrenburgs.com/Default.aspx?tabid=58&EntryID=3.  My problem was I had tried darrenmcleod.com/ as the portal alias but it kept giving me an infinite redirect error.  Then I tried darrenmcleod.com as the portal alias as bahrenburgs suggested and everything is goodness.  Note that when you make a change like this just through the database you need to do something to cause your application to reload, like editing a line in web.config and saving it.

A good guide to the ASP.NET 2.0 Wizard Control can be found here http://steveorr.net/articles/Wizard.aspx

  I wanted to have the Wizard Control Header display the current step’s title, after a little research I found that the ActiveStepChanged event would allow me to do this. So I added an event handler like this:

    Protected Sub Wizard1_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Wizard1.ActiveStepChanged

        Me.Wizard1.HeaderText = Me.Wizard1.ActiveStep.Title

    End Sub

  Except it didn’t set the Header for the first step so I set the HeaderText manually to the first step’s title like this:

        asp:Wizard ID="Wizard1" runat="server" HeaderText="Step 1">

            WizardSteps>

                asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">

                asp:WizardStep>

                asp:WizardStep ID="WizardStep2"...

Read More »

Add a property to your WebUserControl:

Private widthValue As Integer

Public Property Width() As Integer

    Get

        Return widthValue

    End Get

    Set(ByVal value As Integer)

        widthValue = value

    End Set

End Property

Then add a prerender event handler to the WebUserControl, where in this example the MainTable happens to be the outermost container element in the Web User Control with a width attribute:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

    If Me.Width > 0 Then

        Me.MainTable.Width = Me.Width

    End If

End Sub

Then where ever you use the control you can specify the width if you want to:

uc2:MyWebUserControl ID="MyWebUserControl1" runat="server" width="650" />



...

Read More »