Reputation: 177
I got this code in order to build an url for the link using a querystring from the current page. The problem is.... It doens't work. Any suggestions?
<asp:hyperlink ID="link1" runat="server" NavigateUrl='<%@("Equipamentos.aspx?ID_Cliente=")+Request.QueryString ("ID_Cliente").trim.tostring()%>'>Equipamentos</asp:HyperLink>
Upvotes: 1
Views: 2874
Reputation: 11079
As I know you can't use "<%= %>" with server controls. So you can:
1. Leave it as a server control and follow Andrew Hare's (or similar) answer.
2. Use client control: "<a />" and "<%= %>" should work.
Upvotes: 0
Reputation: 4810
Your ASP.NET code should look like this:
<asp:HyperLink ID="link1" runat="server" NavigateUrl=''>Equipamentos</asp:HyperLink>
And then add this in code behind:
this.link1.NavigateUrl = string.Format("Equipamentos.aspx?ID_Cliente={0}", Request.QueryString["ID_Cliente"].Trim());
Upvotes: 1
Reputation: 351638
You are not going to be able to set the NavigateUrl
of the link in this way. Try something like this:
<asp:hyperlink
ID="link1"
runat="server">Equipamentos</asp:HyperLink>
And then in your codebehing or a script tag do this:
link1.NavigateUrl = "Equipamentos.aspx?ID_Cliente="
+ Request.QueryString("ID_Cliente").Trim().ToString();
Upvotes: 0
Reputation: 12975
The
<%@ %>
tags are for directives, such as registering controls. You need a
<%= %>
tag, which is called a code evaluation block.
Something like
<%= (5+5).ToString() %>
is what you need - try your code in there.
Upvotes: 0
Reputation: 26169
Gah, my eyes! Try doing this in code behind instead:
link1.NavigateUrl = "Equipamentos.aspx?ID_Cliente=" & Request.QueryString("ID_Cliente").Trim().ToString()
You have to use "&" instead of "+" because this is VB.NET, not C#.
Upvotes: 2
Reputation: 48098
Try this instead :
<asp:hyperlink ID="link1" runat="server"
NavigateUrl='<%= ("Equipamentos.aspx?ID_Cliente=")
+ Request.QueryString("ID_Cliente").Trim().ToString() %>'>
Equipamentos</asp:HyperLink>
Upvotes: 0