Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 803
  • Last Modified:

Server.UrlEncode an XPath Value

I'm using an asp:XmlDataSource element with an asp:Repeater and the following XPath element works fine, but I need to know how to Server.UrlEncode the output value:

<%#XPath("title") %>

Open in new window


For example if the value was 'Sony T100 Digital Camera'  I want to build an output url like this:

<a href="http://www.example.com/-Sony+T100+Digital+Camera">Sony T100 Digital Camera</a>

When I tried to use something like the following, it gives a server exception error:

<a href="http://www.example.com/-<%=Server.UrlEncode(XPath("url")) %>"><%#XPath("title") %></a>

Open in new window


Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.HttpServerUtility.UrlEncode(string)' has some invalid arguments

Using inline code, how can I get the XPath value of 'title' to be url encoded?
0
thyros
Asked:
thyros
1 Solution
 
Bob LearnedCommented:
I believe that the problem is that the XPath method returns an object, so you need to convert it to a string:

<%=Server.UrlEncode(XPath("url").ToString()) %>
0
 
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now