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
5 Answers, 1 is accepted
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.
Thanks
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.
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 " 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);
}
}
}
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