Who Benefits from this Article?
People just starting in ASP.NET (VB) will benefit most from this article. And those who have been working with ASP.NET but need a refresher.
This is a code page to add to your Toolbox of must-have code.
When building applications in ASP.NET Web Forms using VB.NET, a frequent requirement is passing dynamic data—such as primary keys, user identifiers, or search parameters—from the server-side code-behind to links on the user interface. Seamless data transmission between layers ensures application security, clean page states, and highly contextual user experiences.
This comprehensive guide breaks down the three industry-standard architectural approaches to connecting backend variables directly to presentation-layer links. We explore implementing native ASP.NET HyperLink
Copy
Search Site
Search Google
server controls, deploying Public
Copy
Search Site
Search Google
or Protected
Copy
Search Site
Search Google
page-level properties with server-side inline expressions, and enhancing semantic HTML anchor tags with the runat="server"
Copy
Search Site
Search Google
compiler directive. Each methodology comes complete with precise code samples, architectural advantages, and practical real-world use cases to optimize your enterprise web applications.
[Method 1: The ASP.NET HyperLink Server Control]
The most object-oriented approach in ASP.NET involves using the built-in server control ecosystem. By dropping a native <asp:HyperLink>
Copy
Search Site
Search Google
element onto the webpage markup, the compiler generates a server-side object that can be manipulated in the VB.NET class file during lifecycle events like Page_Load
Copy
Search Site
Search Google
.
[ASP.NET - Frontend Markup (.aspx)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
<asp:HyperLink ID="lnkDynamic" runat="server" Text="Click Here to Visit"></asp:HyperLink>

[ASP.NET - Backend Logic (.aspx.vb)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim recordId As String = "ABC-123"
        lnkDynamic.NavigateUrl = "details.aspx?id=" & Server.UrlEncode(recordId)
    End If
End Sub

Best Used For: Standard enterprise applications utilizing traditional ASP.NET state management where clean, type-safe control manipulation is prioritized over raw HTML structure.
[Method 2: Page Properties and Server-Side Expressions]
When standard HTML semantic tagging must be preserved, developers can bypass server controls entirely by exposing page-level variables. By creating a Public
Copy
Search Site
Search Google
or Protected
Copy
Search Site
Search Google
property in the VB.NET class, the presentation page can directly pull the evaluation using standard ASP.NET server render blocks <%= %>
Copy
Search Site
Search Google
.
[ASP.NET - Frontend Markup (.aspx)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
<a href="<%= ProfileUrl %>">View User Profile</a>

[ASP.NET - Backend Logic (.aspx.vb)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
Public Class DynamicWebPage
    Inherits System.Web.UI.Page

    ' Must be Protected or Public; Private variables throw a compilation error
    Protected Property ProfileUrl As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim userId As String = "9988"
            ProfileUrl = "profile.aspx?user=" & Server.UrlEncode(userId)
        End If
    End Sub
End Class

Best Used For: Integrating with third-party CSS grids, frontend design frameworks (like Bootstrap), or when retaining semantic, lightweight HTML output is critical for client-side scripting.
[Method 3: Semantic HTML with runat="server"
Copy
Search Site
Search Google
]
This hybrid approach balances the benefits of standard HTML tags with server-side control accessibility. Adding the runat="server"
Copy
Search Site
Search Google
attribute instructs the page framework to convert the basic <a>
Copy
Search Site
Search Google
anchor element into an HtmlAnchor
Copy
Search Site
Search Google
control in the page tree, making its attributes directly editable in code-behind.
[ASP.NET - Frontend Markup (.aspx)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
<a id="htmlLink" runat="server">Go to Destination</a>

[ASP.NET - Backend Logic (.aspx.vb)]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim tokenCode As String = "XYZ789"
        htmlLink.HRef = "secure/download.aspx?token=" & Server.UrlEncode(tokenCode)
    End If
End Sub

Best Used For: Legacy system updates where clean markup must remain intact, but developers require quick server-side access to tag attributes without rewriting frontend pages entirely.
[Critical Implementation Best Practices]
Other Articles Related to this Entry.Mastering Web Forms: 3 Ways to Pass Values from C#.NET Code-Behind to Frontend Links«