title: HttpUtility.UrlEncode() and Server.UrlEncode() are not encoding the URL in asp.net 4.0
body: <p>I am trying to encode the url using <code>HttpUtility.UrlEncode</code>,
  but not able to make it work. <code>HyperLink</code> control is in the
  template field of gridview.</p>
  
  <p>Can anyone please help me out with this?</p>
  
  <p>I have tried changing the target application and by adding
  <code>System.Web</code> reference to project but still not able to Encode
  the url. </p>
  
  <p>Please guide me.</p>
  
  <p>Following is part of my code:-</p>
  
  <pre><code>&lt;asp:HyperLink ID="lnkDetailsPage" runat="server" NavigateUrl='&lt;%# string.Format("~/YellowPages/YellowDetailView.aspx?CustomerId={0}",HttpUtility.UrlEncode(Eval("CustomerId").ToString())) %&gt;'&gt;&lt;/asp:HyperLink&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>