Dynamically create HTML anchor tag with server-side click event
Posted on 2006-11-02
I am dynamically creating a navigation menu with tabs for the different pages/topics of a survey. I'm doing this by concatenating the HTML code at runtime and setting it as the innerhtml property of a DIV tag on the page. I need to make the anchor tags trigger a server-side click event rather than set the HREF property. This is because I'm using the page's viewstate to store the user's answers as they progress through the survey rather than make a trip to the SQL database for each tab.
Can anyone tell me if this is possible, or if I'm overlooking something obvious? If more information/code samples are needed, please let me know. Thanks in advance!
P.S. If this seems overly complicated, I agree. But I have requirements for compatibility with css, etc.
Protected WithEvents header As System.Web.UI.HtmlControls.HtmlGenericControl
Dim strMenuHtml As New StringBuilder("<ul>")
' Loop through each page in the form and add a menu item
For i As Integer = 1 To objForm.PageCount - 1
If i = intPage Then
strMenuHtml.Append("id=""menuOption" & i & """ ")
strMenuHtml.Append("runat=""server"" command=""" & i & """><a href=""Default.aspx?Form=" & intForm & "&Page=" & i & """>" & GetPageCaption(i) & "</a></li>")
' Insert the HTML code into the menu DIV tag
header.InnerHtml = strMenuHtml.ToString