Solved

Server.UrlEncode an XPath Value

Posted on 2011-02-15
3
759 Views
Last Modified: 2012-06-21
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
Comment
Question by:thyros
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
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
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now