Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Utility Function to Create an Anchor Tag

A few month's ago I created a little method to help me automate or at least make uniform the creation of anchor tags in my code.  I decided to revisit this method because I had made it more or less specific to a particular page I really needed it for.  Today I made it a little more generic.

Public Function BuildLink(ByVal sAnchor As String, ByVal Param() As ExParameter, _

ByVal URL As String, ByVal Attributes As String) As String

Dim sParams As String = ""

Dim p As ExParameter

For Each p In Param

If sParams = "" Then

sParams = "?" & p.ParamName & "=" & p.ParamValue

Else

sParams = sParams & "&" & p.ParamName & "=" & p.ParamValue

End If

Next

Return String.Format("<a href=""{0}{1}"" {3}>{2}</a>", _

URL, sParams, sAnchor, Attributes)

End Function

There are still some mannual work invovled here and I hope to expand this out a little more in the near future.  I also created a little structure to help with the querystring parameters.

Public Structure ExParameter

Public ParamName As String

Public ParamValue As String

End Structure

I think my next version will have a few supporting classes that will help with the attributes and the parameters.  I use this function when I implement the ITemplate technique.

Posted: Wednesday, August 30, 2006 9:23 AM

by Chris Love
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS