Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi..

I am trying to encode the url using HttpUtility.UrlEncode,
but not able to make it work. HyperLink control is in the
template field of gridview.

Can anyone please help me out with this??

I have tried changing the target application and by adding
System.Web reference to project but still not able to Encode
the url.

Please guide me.

Following is part of my code:-

ASP.NET
<asp:HyperLink ID="lnkDetailsPage" runat="server" NavigateUrl='<%# string.Format("~/YellowPages/YellowDetailView.aspx?CustomerId={0}",HttpUtility.UrlEncode(Eval("CustomerId").ToString())) %>'></asp:HyperLink>



Thanks in advance.
Posted
Updated 29-Dec-13 19:53pm
v3
Comments
Sergey Alexandrovich Kryukov 30-Dec-13 1:40am    
This function does work, and it is unrelated to ASP.NET or any other particular application type, period.
What do you call this function in your code and what comes on input?
—SA
bhagyap 30-Dec-13 1:45am    
I have Gridview,within which included the anchor tag in its template field which lets me navigate to next page based on the CustomerId.

I have even tried with this too:

<asp:HyperLink ID="lnkDetailsPage" runat="server" NavigateUrl='<%# string.Format("~/YellowPages/YellowDetailView.aspx?CustomerId={0}",HttpUtility.UrlEncode(Eval("CustomerId").ToString())) %>'>

1 solution

hi Try this..

ASP.NET
<asp:HyperLink ID="lnkDetailsPage" Text="click here" runat="server" NavigateUrl='<%# "~/YellowPages/YellowDetailView.aspx?CustomerId=" + HttpUtility.UrlEncode(Eval("CustomerId").ToString())  %>'>
                   </asp:HyperLink>


Text="click here"



whenever you are using Hyperlink you should assign the Text value.

if the Text value is empty , then the link wont appear on the screen.
 
Share this answer
 
Comments
bhagyap 31-Dec-13 0:14am    
Thanks for reply. I tried with it but its not working.
Karthik_Mahalingam 31-Dec-13 1:35am    
what error u r getting
bhagyap 1-Jan-14 0:26am    
Am not getting any error but the url isn't getting encoded.
Karthik_Mahalingam 1-Jan-14 0:45am    
post your encoded url

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900