RadFilter not able to use double quote

6 posts, 1 answers
  1. Brett
    Brett avatar
    8 posts
    Member since:
    Feb 2011

    Posted 21 Jun 2011 Link to this post

    Hi,

    I have a RadFilter on a page which has a RadGrid with data in it.  The data in the grid may or may not contain a " in it.
    If you currently attempt to use the filter with "Contains" and " in the text box, the following javascript error is thrown:

    Sys.WebForms.PageRequestManagerServerErrorException: Unterminated string literal

    It is a requirement that I be able to use the filter to find data that has a " in it.

    My version of Telerik dlls is: 2011.1.413.35 (Q1 2011) ASP.NET AJAX

    In an attempt to solve this, I have tried to do a replace before the OnApplyExpressions event finishes with Replace("\"", "\\\"") however this yields the same error as above.  The thought behind this was that I could escape it so that the javascript would no longer end prematurely.

    Any help would be appreciated.
    Thanks
  2. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 24 Jun 2011 Link to this post

    Hi Brett,

    You need to escape double quotes in RadFilter's text fields. The exception you are getting indicates an error in the dynamic LINQ parser used to parse your filter expression. As string values in the filter expression are already escape, you need to additionally escape double quotes. You can use RadFilter's ApplyExpressions event to loop through all the parts of your expression and escape double where needed. Here is a sample implementation:

    protected void RadFilter1_ApplyExpressions(object sender, RadFilterApplyExpressionsEventArgs e)
    {
        HandleQuotes(e.ExpressionRoot);
    }
     
    protected void HandleQuotes(RadFilterGroupExpression expression)
    {
        var expressions = expression.Expressions;
        foreach (var expr in expressions)
        {
            if (expr is RadFilterSingleValueExpression<string>)
            {
                var stringExpr = (RadFilterSingleValueExpression<string>)expr;
                stringExpr.Value = stringExpr.Value.Replace("\"", "\"\"");
            }
     
            if (expr is RadFilterGroupExpression)
            {
                HandleQuotes((RadFilterGroupExpression)expr);
            }
        }
    }

    The above HandleQuotes() method will replace your double quotes in string values into a pair of double quotes.

    Veli
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brett
    Brett avatar
    8 posts
    Member since:
    Feb 2011

    Posted 24 Jun 2011 Link to this post

    Thank you for the reply.  This does eliminate the Javascript error (after a little debugging of my own).  However I am not getting any results that contain the " in them.  Instead I get an empty grid.

    Thanks
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 29 Jun 2011 Link to this post

    Hi Brett,

    I am attaching the test page I used for this scenario. Let me know how this works for you and what is different in your case.

    Veli
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Brett
    Brett avatar
    8 posts
    Member since:
    Feb 2011

    Posted 29 Jun 2011 Link to this post

    I have found what was different.  The page in the example has a plain text " while I have encoded all of my data to be HTML safe.  I am using HttpUtility.HttpEncode on my data source, thus a " is actually &quot; which is why no results were returning.  Its the little things in life that get you. Below is the modified version that now properly returns results for me.

    Thank you for the help and response.

    protected void HandleQuotes(RadFilterGroupExpression expression)
            {
                var expressions = expression.Expressions;
     
                foreach (var expr in expressions)
                {
                    if (expr is RadFilterSingleValueExpression<string>)
                    {
                        var stringExpr = (RadFilterSingleValueExpression<string>)expr;
                        stringExpr.Value = stringExpr.Value.Replace("\"", HttpUtility.HtmlEncode("\""));
                    }
     
                    if (expr is RadFilterGroupExpression)
                    {
                        HandleQuotes((RadFilterGroupExpression)expr);
                    }
                }
            }
  7. Raji
    Raji avatar
    56 posts
    Member since:
    Jul 2011

    Posted 29 Jul 2011 Link to this post

    Hi Veli,

    The code is really helpful. I am using .Net 2.0 so I can not use 'var' keyword specified in your code. Is their an alternative code that I can use to loop through the expressions using .Net 2.0. Early help will be appreciated.

    Thanks,
    Raji
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017