1

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.

1 Answer 1

2

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 &

Sign up to request clarification or add additional context in comments.

3 Comments

That's great thank you SeraphnimFoA, I used the code behind method you suggested
If you do that make sure that you don't append the Language to the Link more than once.
I know this is very old, but should option 1 actually work? I tried it, but you still don't get the desired result from the expression.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.