RadTextBox, HTML Text, and AJAX

2 posts, 0 answers
  1. Xorcist
    Xorcist avatar
    98 posts
    Member since:
    Apr 2009

    Posted 14 Jan 2010 Link to this post

    Typing anything close to HTML into a RadTextBox seems to break it when it goes over the wire. I've tried escaping (encoding) it via javascript in the OnRequestStart, but that didn't seem to work... any ideas on the proper way to handle this (and without using a RadEditor).
  2. Dimo
    Admin
    Dimo avatar
    8482 posts

    Posted 15 Jan 2010 Link to this post

    Hi Xorcist,

    The problem is caused by security restrictions in the ASP.NET framework and is not directly related to RadTextBox. Please refer to:

    http://www.asp.net/learn/whitepapers/request-validation/

    Since there is no good and proper way to intercept postbacks and change submitted values on the fly, I can suggest you to use some custom client event (e.g. a button click) and encode values before the actual submit action.

    If you prefer using more hackish methods, here are two for you:


    1.  Override the  WebForm_OnSubmit  function, which handles all postbacks. For example

    http://www.duncangunn.me.uk/dasblog/2008/03/07/InterceptingWebFormOnSubmit.aspx


    2. Change the value of the request body on the fly:


    <%@ Page Language="C#" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>No Title</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="AJAX" />
        </ContentTemplate>
    </asp:UpdatePanel>
     
    <script type="text/javascript">
     
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
     
    function initializeRequestHandler(sender, args)
    {
        var requestBody = args.get_request().get_body();
        //args.get_request().set_body(.................);
    }
     
    </script>
     
    </form>
    </body>
    </html>



    Greetings,
    Dimo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top