1

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>
2
  • I'd suggest you say what "it doesn't work" means. Commented Jul 2, 2009 at 13:52
  • The link appears as a link but it doesn't have any link..... Commented Jul 2, 2009 at 13:54

6 Answers 6

2

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#.

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

3 Comments

Thank you very much... At least someone nice with a useful answer
The "ToString()" at the end is when you are not sure that Trim() returns String?:)
Actually "+" works for string concatenation, too. "&" is preferred because there's no chance that it will do an implicit cast followed by an arithmetic add.
1

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());

Comments

0

Try this instead :

<asp:hyperlink ID="link1" runat="server" 
  NavigateUrl='<%= ("Equipamentos.aspx?ID_Cliente=") 
  + Request.QueryString("ID_Cliente").Trim().ToString() %>'>
  Equipamentos</asp:HyperLink>

1 Comment

Why downvote without an explanation ? Exactly, I have done this way in many places in my project.
0

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.

Comments

0

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();

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.