Concatenating a string in a querrystring of a <a> link in c# created through asp.net
-
10-07-2019 - |
Question
I can already send something in the querrystring:
<a href='Exibe.aspx?var='lalala''>
but i'd like to send a string instead of lalala, and when i try to concatenate normally in the response.write with "+" signs, it just doesn't. it creates the url only with the part before the "+".
facts: the string has a value i can concatenate it with other string and it works i can use the querrystring with something i write
thank you
UPDATE: code that doesn't work:
responde.write("<a href='Exibe.aspx?nome='" + nome(0) + "''> click here </a>");
code that works but doesn't do what i want (sends "VALUE" not my string)
responde.write("<a href='Exibe.aspx?nome='VALUE''> click here </a>");
i'm really new at this.. sorry
Solution
Are you looking for HttpUtility.UrlEncode or are you looking for something to build the Uri like UriBuilder ? Either way you should be able to google up some examples.
OTHER TIPS
Why not simply use a hyperlink server control? That way you have full control over the link element from you're code:
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
HyperLink1.NavigateUrl = "http://whereever.com/Default.aspx?Blah=whatever";
Also, with query strings you dont need to use quotation marks around each parameter.
This:
response.write("<a href='Exibe.aspx?nome=VALUE'> click here </a>");
Will pass the string "VALUE" through.