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.