Tuesday, December 06, 2005 6:48:13 PM UTC :: Filed Under ASP.NET | Web Design

I like adding help messages to web forms, but I find that these help messages can often make the page very long.  Since a user won’t like need a help message once he has read it, it’s nice to be able to hide the message.

With that in-mind, the JavaScripts below are nice samples of scripts that will display or hide content that is within a specified <DIV> tag.  They can be called from a single button or hyperlink:

function toggleDiv(divName) {
    thisDiv = document.getElementById(divName);
    if (thisDiv) {
        if (thisDiv.style.display == "none") {
            thisDiv.style.display = "block";
        }
        else {
            thisDiv.style.display = "none";
        }
    }
    else {
        alert("Error: Could not locate div with id: " + divName);
    }
}

function toggleDiv(divName) {
    var thisDiv = document.getElementById(divName);
    if (thisDiv) thisDiv.style.display = !thisDiv.offsetWidth ? "block" :"none";
    else alert("Error: Could not locate div with id: " + divName);
}

Tuesday, November 29, 2005 10:33:12 PM UTC :: Filed Under ASP.NET | VB.NET

I recently took on the project of trying to create my own Business Logic Layer (BLL) and Data Access Layer (DAL) in a personal web project so I could understand how the various layers of n-tier architecture are supposed to work.  I didn’t get very far before I realized that allowing NULL database values (System.DBNull.Value) in various fields in my database was going to give me a large headache :'(

After doing a lot of research, I didn’t come-up with too many satisfactory methods for dealing with DBNulls.  At best, it seemed like I’d have to write all sorts of methods for converting DBNulls to either a default value for each data type (I.e., define an integer to default to zero, a string defaults to String.Empty, a date defaults to DateTime.MinValue, etc.) or use the new VB.NET 2.0 Nullable Types and set each data type to Nothing.  This sounded like a lot of work and a lot of code… more code = more errors!

I read a few articles on using Generic Types in VB.NET 2.0 and it appeared to me as though they could be the answer to my prayers:  Create one generic method that can check for DBNulls for all data types.  A blog post by Saravana Kumar shows a way to accomplish this using C#. However, C# has a keyword default which doesn’t exist in VB.NET (at least not that I could find.)  This keyword apparently returns the default value for each data type, just like I wanted!

After much tinkering, here is what I came-up after trying to convert Saravana’s code to VB.NET:

Public Shared Function ConvertDBNull(Of T)(ByVal obj As Object) As T
    If (obj Is System.DBNull.Value) Then
        obj = Nothing
    End If
    Return CType(obj, T)
End Function

So far, it seems to work!  For example, with the following code:

Dim oSomeTestObject As Object = System.DBNull.Value
Dim strResult As String = ConvertDBNull(Of Integer)(oSomeTestObject)

The value of strResult is returned as a zero.  Another example:

Dim oSomeTestObject As Object = System.DBNull.Value
Dim strResult As String = ConvertDBNull(Of Date)(oSomeTestObject)

The value of strResult is returned as a “12:00:00 AM”. For most dates that I display, I always format them as MM/dd/yyyy, so a date value only exposing time won't show.

I tested this new method on my BLL, and so far it works great! w00t! If you have a better method for dealing with DBNulls in your Business Logic, let me know… I’m all ears!

Tuesday, November 29, 2005 6:24:11 PM UTC :: Filed Under ASP.NET

The December issue of MSDN Magazine has a nice listing of add-ins for Visual Studio, most of which are free:
Visual Studio Add-Ins Every Developer Should Download Now

Monday, November 28, 2005 10:37:16 PM UTC :: Filed Under ASP.NET

One thing it took me way too long to learn with Visual Studio 2003 is how to customize the default file templates.  Well, it didn’t take me long to customize the templates once I knew where they were, it was finding them that was hard. ;-) 

For example, when you add a new web form to a project, you don’t have to put-up with all the garbage tags in the HTML page header that Visual Studio auto-magically generates. You can modify the ASPX page template to show what you want so you don’t have to modify each new file.  The same can be done with class files, XML, etc.

The template customization feature of VS.NET 2005 is pretty nice and the guys and gals at MSDN have already created a lot of documentation for template customization:

MSDN2: Visual Studio Templates

Monday, November 28, 2005 9:45:14 PM UTC :: Filed Under ASP.NET

There are a couple of web sites out there that cover exactly how I feel most of the time while programming… here’s one of them: http://thedailywtf.com/

Monday, November 28, 2005 4:12:43 PM UTC :: Filed Under ASP.NET
Navigation
On this page....
Search
Archives
<December 2005>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor