Hi Everyone! Thanks for your help!
Little info to get you started: On our website, we currently have forms and brochures pages for people to download. (Example:
https://www.mosers.org/Members/Forms.aspx). Currently, these are written out programatically by reading a content management system (basically a database), looping through the items, writing out their values and adding <li> tags around each. I want to add tracking to these forms so we can see usage. I plan to write the form name, among other information to an MS SQL database.
To try and accomplish this, I'm writing these links out instead as asp linkbuttons so that when they are clicked I can raise an event to write the tracking data to the db. Again I'm looping through the items, assigning the item's title to the linkbutton.text property. Next is where it gets tough (at least for me!)
At first, to make the links work, I assigned the item's path (address) to the linkbuttons href attribute. But when I do that, yes the link then works, but I get no click event. The event never gets raised.
So then I've tried leaving the href attribute alone and just assigning the path to another attribute of the linkbutton. For instance, Ive done " Link.Attributes.Add("title
", path). Now when the linkbutton is clicked the event is raised, but I'm stuck there because I can't grab the associated path (url) I need from the linkbutton I just clicked. I'd like to somehow grab the title and path from whatever link I'm clicking on, but I get nothing. Is this possible?
Here's a simple example of what I'm doing:
'Loops through links and write them out in <ol><li> tags
output.Write("<ol>")
If (multiselectfield Is Nothing) Then
'output.Write("Error finding Forms")
Else
Dim items() As Sitecore.Data.Items.Item = multiselectfield.GetItems
If ((Not (items) Is Nothing) AndAlso (items.Length > 0)) Then
Dim i As Integer = 0
Dim path As String
Do While (i < items.Length)
path = Sitecore.Links.LinkManager
.GetItemUr
l(items(i)
)
output.Write("<li>")
Link.Text = FieldRenderer.Render(items
(i), "Title")
Link.Attributes.Add("alt",
path)
Link.Attributes.Add("title
", FieldRenderer.Render(items
(i), "Title"))
Link.RenderControl(output)
output.Write("</li>")
output.WriteLine()
i = (i + 1)
Loop
End If
End If
output.Write("</ol>")
'Linkbutton click event (raised from each linkbutton)
Protected Sub Link_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Link.Click
Dim text As String
text = Link.Attributes("title")
End Sub