RadPrompt and HtmlEncode Values

2 posts, 0 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 23 May 2012 Link to this post

    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?
  2. Marin Bratanov
    Marin Bratanov avatar
    3908 posts

    Posted 28 May 2012 Link to this post


    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)
        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, "'"));

    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.
Back to Top