This is a migrated thread and some comments may be shown as answers.

RadPrompt and HtmlEncode Values

1 Answer 39 Views
Window
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 24 May 2012, 04:29 AM
I am building a small photo gallery where individual items can have a caption associated with them and changing this value is completed with a simple radprompt() call. The problem I have run into is since user's could enter characters that would break javascript (such as apostrophe's) I do an HtmlEncode on the original value which is filled into the prompt box as the default value. When the prompt displays though, the HtmlEncoded characters (such as &#39 for an apostrophe) are shown in the prompt box which is obviously not ideal. Is there a way to get the correct characters to show for the default value?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 28 May 2012, 04:23 PM
Hello,

An apostrophe can be put in the radprompt default value and it will be returned properly, e.g.:
<telerik:RadWindowManager runat="server" ID="rwm1"></telerik:RadWindowManager>
<asp:Button ID="Button1" Text="prompt" OnClientClick="callPrompt(); return false;" runat="server" />

function callPrompt()
{
    function callBackFn(arg)
    {
        alert(arg);
    }
    var defaultValue = "some'text ' with'apostrophes '";
    radprompt("message", callBackFn, 300, 200, null, "title", defaultValue);
}

If you are expecting values that can cause problems you can use, for example, regular expressions to remove them either from the initial value you pass, or from the returned value in the callback function. The following function shows an example that will change a sign to its encoded value and then show it correctly in the dialog:
var defaultValue = "some value ' here";
defaultValue = defaultValue.replace(/&#39;/g, "_myApostrophePlaceholder_");
var rp = radprompt("enter value", callBackFn, 300, 200, null, "title", defaultValue);
var promptInput = $telerik.$(".rwDialogInput", rp.get_popupElement());
promptInput.val(promptInput.val().replace(/_myApostrophePlaceholder_/g, "'"));


Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
digitall
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or