Dplusa25
Dplusa25

Reputation: 31

Adding variable to an href ASP.NET

I am trying to add the result of Request.QueryString('x') (VB script) to an href as shown below:

<a runat="server" href="~/Reports/ProductionReport.aspx?SiteCode=<%=Request.QueryString('SiteCode')%>">Production Details</a>

There is something wrong with my syntax, but I can't figure out what. If I click the link, it redirects me to a page that is:

"~/Reports/ProductionReport.aspx?SiteCode=<%=Request.QueryString('SiteCode')%>"

instead of "~/Reports/ProductionReport.aspx?SiteCode=value"

Could someone give me the correct syntax?

Upvotes: 0

Views: 2906

Answers (1)

VDWWD
VDWWD

Reputation: 35514

Remove the runat="server" tag if you don't need it.

 <a href="/Reports/ProductionReport.aspx?SiteCode=<%= Request.QueryString("SiteCode") %>">Production Details</a>

Or create a HyperLink Control and set the NavigateUrl from code behind

<asp:HyperLink ID="HyperLink1" runat="server">Production Details</asp:HyperLink>

HyperLink1.NavigateUrl = "/Reports/ProductionReport.aspx?SiteCode=" + Request.QueryString("SiteCode")

Upvotes: 2

Related Questions