v3ga
v3ga

Reputation: 177

ASP.NET Querystrings

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

Answers (6)

Kamarey
Kamarey

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

Nelson Reis
Nelson Reis

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

Andrew Hare
Andrew Hare

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

JoshJordan
JoshJordan

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

Matthew Groves
Matthew Groves

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

Canavar
Canavar

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

Related Questions