Solved

Help with combining encodeURIComponent() with Mailto (Gridview)

Posted on 2014-01-22
3
494 Views
Last Modified: 2014-03-26
Hello,

I have the following within a gridview.

<asp:TemplateField>
<ItemTemplate>
<a href='mailto: <%# Eval("email") %> ?Subject=Notification <%# Eval("Number")%> - <%# Eval("Description") %> '>
Send Notification</a>
</ItemTemplate>
</asp:TemplateField>

Open in new window


This kinds of works up until <%# Eval("Description") %> contains a special character, i.e. %

I need to preserve this.  I read this could be done by using encodeURIComponent().  I found an example of this:

<script language="JavaScript"><document.write("<a href=\"mailto:recipient@example.com?subject=" + encodeURIComponent("When, when is now? (if \"now\" is here)") + "\">mail me!</a>")</script>

However I can’t seem to apply it succesfully to my code.  Can anyone help please?
0
Comment
Question by:andyw27
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39802778
You can run encodeURIComponent from a console to get the result as it's static :
<script language="JavaScript"><document.write("<a href=\"mailto:recipient@example.com?subject=When%2C%20when%20is%20now%3F%20(if%20%22now%22%20is%20here)\">mail me!</a>")</script>

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39802857
A server-side solution using the bound data would be to replace line 3 of your posted code to:
<a href='mailto:<%# Eval("email") %>?Subject=<%# Server.UrlEncode("Notification " & Eval("Number") & " - " & Eval("Description"))%>'>

Open in new window

0
 

Author Comment

by:andyw27
ID: 39847397
Thanks for the suggestions, I'll give this a go.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

680 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