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

x
?
Solved

Help with combining encodeURIComponent() with Mailto (Gridview)

Posted on 2014-01-22
3
Medium Priority
?
571 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

916 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