Solved

Help with combining encodeURIComponent() with Mailto (Gridview)

Posted on 2014-01-22
3
460 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the suggestions, I'll give this a go.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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

9 Experts available now in Live!

Get 1:1 Help Now