Greg
Greg

Reputation: 197

asp.net dynamic variable in hyperlink

I'm having a little trouble using an asp.net:hyperlink control.

<asp:HyperLink ID="someId" runat="server" NavigateUrl="pages/somepage.aspx?language=<%=CurrentLanguageNo%>"></asp:HyperLink>

the resulting url is like this

http://localhost/web/standard/pages/somepage.aspx?language=<%=CurrentLanguageNo%>

but obviously I don't want it to literally be <%=CurrentLanguageNo%> but rather the value of the variable.

Upvotes: 1

Views: 632

Answers (1)

SeraphimFoA
SeraphimFoA

Reputation: 466

That's because you need to specify the entire NavigateUrl within the <%=%>

so you have 2 choices (actually there are plenty more but let's not waste time):

NavigateUrl='<%= "pages/somepage.aspx?language=" + CurrentLanguageNo%>'

Or you put directly the entire string in the variable CurrentLanguageNo

Other possibility is to keep your NavigateUrl="pages/somepage.aspx?language=" and then on the code behind add CurrentLanguageNo

objLink.NavigateUrl += CurrentLanguageNo;

If you use VB.NET remember to replace + with &

Upvotes: 2

Related Questions