Capturing an Ampersand in Query String Macro

Kevin Kim-Murphy asked on September 17, 2015 16:28

In my Online Form field I am trying to capture the value of a query string parameter that may have special characters (like "&", "!", or "-").


Page URL:

In the field's default value I have placed the Query String Macro: {?parameter?}

And when I submit the form the value captured in the field is: "Me"

My expectation is that the value captured in the field would be the full parameter: "Me & Julio Down by the School Yard"

Any advice for allowing the Query String Macro to include those special characters?

Please let me know. Thanks!


Correct Answer

Juraj Komlosi answered on September 18, 2015 12:29

Hi Kevin,

to achieve your goal you have to transform the "SongTitle" into URL-encoded string in your transformation.

It should look like that: <a href="/pagename?parameter=<%# URLHelper.URLEncode(ValidationHelper.GetString(Eval("SongTitle"),"")) %>">Contact Us

Now if the song title contains an ampersand, e.g. "Me & Julio Down by the School Yard" it will be transformed into URL-encoded string "Me+%26+Julio+Down+by+the+School+Yard".

If you use the query macro {?parameter?} in your form fields, you should see the value you expect - "Me & Julio Down by the School Yard".

Hope it will help you.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Joshua Adams answered on September 17, 2015 16:39

Seems like the best way to handle this would be following something like this:

It may be easier to control the query string and encoding/decoding. Just a thought.

1 votesVote for this answer Mark as a Correct answer

Kevin Kim-Murphy answered on September 17, 2015 18:22


Thank you. So this does help a lot - but but I cannot actually solve the problem entirely... I am thinking that maybe the Transformation that creates the Query String itself needs to be modified. So here is my follow up question:

Is there are way to encode special characters in a Transformation to hex so that the "&" would actually be "%26"?

I was looking at the text manipulation transformation methods: <%# Eval("NewsTitle", true) %> but that did not seem to work.

The query string in my example above is actually generated via a Transformation on another page and passed in a URL of a link.

<a href="/pagename?parameter=<%# Eval("SongTitle") %>">Contact Us

Resulting in the URL:

Per the article you posted it does work if that URL is actually:

Let me know if you can.

Thanks Kevin

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on September 17, 2015 19:06

You may be able to use this transformation method, haven't tested it, but I would think it should work for you.

<%# HTMLEncode("Sample text <br />") %>

0 votesVote for this answer Mark as a Correct answer

Kevin Kim-Murphy answered on September 17, 2015 21:39

That transformation doesn't appear to work. Maybe I am implementing it wrong - but it also seems that that transformation is designed to retain HTML characters that already exist but not convert text characters to HTML (or hex).

Been messing around with a javascript solution - but it seems that I should be able to do one of the following using some combination of Transformation syntax:

a) Strip out special characters (since the value I want to pass to the Query String is from a text field in Kentico the user can enter all sorts of special characters... like &, ', !, -, etc) as the value is placed by the transformation on the page...


b) Convert special characters to HEX when pulling the value from the database.

Either way I was hoping that Kentico had a solution for this so that I don't have to build a javascript or equivilant work around.

Please let me know - if you have any suggestions.

Thanks Kevin

0 votesVote for this answer Mark as a Correct answer

Dextor Arron answered on September 21, 2017 15:35

To start with, by considering them a man with a disability and not a custom curriculum character. Custom curriculum is a type of training, it doesn't portray a man. So you aren't headed toward a decent began. Individuals with in-capacities are as unique in relation to each other as individuals are without. Try not to accept anything if the remedy around one individual with an incapacity, help with assignment is likewise valid for someone else with a similar handicap. There are loads of rules for essayist. There is an AP style-book on inability.

0 votesVote for this answer Mark as a Correct answer

Madigan McCauley answered on November 17, 2017 10:43

Thank you for this. We also had problem like this here in our great essays service. And you really helped us with this question and, of course, answer. It is really hard to deal with URLs. And it is very important to do this, because we have to optimize our educational resource in order to help students. So Juraj Komlosi and Joshua Adams for great ideas about solution of this problem.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.