
Varinder Kumar
Top achievements
Rank 1
Varinder Kumar
asked on 02 Sep 2010, 06:19 AM
Hello,
I am using Sitefinity 3.7 with RadControls (RadFilter and RadGrid). By programmatically I am setting radfilter by giving filter string (eg. ([Val] = 2)) with the following code:
var eq = new RadFilterEqualToFilterExpression<string>(columnName);
RadFilter1.RootGroup.AddExpression(eq);
eq.Value = columnValue;
RadFilter1.RecreateControl();
RadFilter1.FireApplyCommand();
It's working fine when I am using this code on button clicks event and the output is like this code is set the filter (visually) in RadFilter and apply also.
The issue is when I am trying to execute this code on Page_Load under !IsPostBack block, I am getting the following exception:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 418:
Line 419: //displaying the conditions while recreate the control
Line 420: RadFilter1.RecreateControl();
Line 421:
Line 422: RadFilter1.FireApplyCommand();
Source File: c:\Program Files\telerik\Sitefinity3.7\WebSites\MySite\App_Code\clsBAL.cs Line: 420
Stack Trace:
For this I try to use Page_LoadComplete event, but no luck, because we are using the usercontrol as:
public partial class UserControl_xanc_grid : System.Web.UI.UserControl
{
}
So, can you please suggest me how can I set the filter programmatically on page_load (after page load).
Thanks,
Varinder Kumar
9 Answers, 1 is accepted
0

Jay
Top achievements
Rank 1
answered on 03 Sep 2010, 10:51 AM
Hey Varinder
Do you have FieldEditor with FIeldName same as columnName for the expression? Other reason could be if you have set FilterContainerID and the container is not yet bound thus the filter control has not populated its FieldEditors collection.
Cheers,
J J Okocha
Do you have FieldEditor with FIeldName same as columnName for the expression? Other reason could be if you have set FilterContainerID and the container is not yet bound thus the filter control has not populated its FieldEditors collection.
Cheers,
J J Okocha
0

Varinder Kumar
Top achievements
Rank 1
answered on 06 Sep 2010, 04:15 PM
Hello J J Okocha,
Thanks for your reply.
I am doing all the things programmatically and I am not using FilterContainerID regarding this task.
Any other suggestion are welcome.
Thanks,
Varinder Kumar
Thanks for your reply.
I am doing all the things programmatically and I am not using FilterContainerID regarding this task.
Any other suggestion are welcome.
Thanks,
Varinder Kumar
0
Hi Varinder,
In case you are adding the RadFilter control dynamically, you should first make sure it is added to the page controls collection and then call its methods. Check it out and if the issue persists, I would ask you to share the whole code of the page/user control.
Kind regards,
Iana
the Telerik team
In case you are adding the RadFilter control dynamically, you should first make sure it is added to the page controls collection and then call its methods. Check it out and if the issue persists, I would ask you to share the whole code of the page/user control.
Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Robert
Top achievements
Rank 1
answered on 09 Sep 2010, 11:56 PM
I am running into the same sort of issue.
I am binding the RadFilter to a RadGrid.
The RadFilter expressions are saved to and loaded from a database. I used examples in previous posts in this forum provided by Telerik to do this. I can save my expressions fine.
I can load them as well, but they are not immediately applied to the Grid on initial page load. If you click the Apply button, the expressions are applied to the grid and the data is filtered.
If I attempt to call
I am binding the RadFilter to a RadGrid.
The RadFilter expressions are saved to and loaded from a database. I used examples in previous posts in this forum provided by Telerik to do this. I can save my expressions fine.
I can load them as well, but they are not immediately applied to the Grid on initial page load. If you click the Apply button, the expressions are applied to the grid and the data is filtered.
If I attempt to call
RadFilter1.FireApplyCommand();
or
or
RadFilter1.RecreateControl();
in Page_Load I receive an Object Reference not set to an object error.
I need to have the RadFilter apply the loaded expressions when the page is first loaded.
Thanks for any help.
in Page_Load I receive an Object Reference not set to an object error.
I need to have the RadFilter apply the loaded expressions when the page is first loaded.
Thanks for any help.
0
Hello Robert,
Please find the attached sample illustrating the desired functionality. Check it out and let me know if it works for you.
Greetings,
Iana
the Telerik team
Please find the attached sample illustrating the desired functionality. Check it out and let me know if it works for you.
Greetings,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Robert
Top achievements
Rank 1
answered on 11 Sep 2010, 01:51 AM
Unfortunately, I get the same result.
I am creating the RadGrid dynamically as the columns in the grid are based off of what is in the database as well.
I create the grid in Page_Init, like so:
In Page_Load, I do the following:
Apply Expressions event:
Same error occurs on RadFilter1.FireApplyCommand(); in Page_Load.
I am creating the RadGrid dynamically as the columns in the grid are based off of what is in the database as well.
I create the grid in Page_Init, like so:
Report _Report;
RadGrid _Grid;
protected
void
Page_Init(
object
sender, EventArgs e)
{
string
reportId = Request.QueryString[
"ReportId"
];
if
(!
string
.IsNullOrEmpty(reportId))
{
int
Id =
int
.Parse(reportId);
_Report = ReportManager.GetById(Id);
RadGrid grid =
new
RadGrid();
grid.ID =
"RadGrid1"
;
grid.AutoGenerateColumns =
false
;
grid.DataSourceID =
"lds1"
;
grid.AllowSorting =
true
;
grid.AllowFilteringByColumn =
true
;
grid.ClientSettings.AllowColumnsReorder =
true
;
grid.MasterTableView.IsFilterItemExpanded =
false
;
CreateReport(ReportManager.GetReportFields(Id), grid);
this
.PlaceHolder1.Controls.Add(grid);
_Grid = grid;
}
}
In Page_Load, I do the following:
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid grid = (RadGrid)
this
.PlaceHolder1.FindControl(
"RadGrid1"
);
this
.RadFilter1.FilterContainerID = grid.ID;
if
(!Page.IsPostBack)
{
if
(_Report !=
null
)
{
this
.hidReportFilter.Value = _Report.FilterExpression;
var persister =
new
ExpressionPersister();
((IStateManager)RadFilter1.RootGroup).LoadViewState(persister.Load(_Report.FilterExpression));
RadFilter1.FireApplyCommand();
}
}
}
Apply Expressions event:
void
RadFilter1_ApplyExpressions(
object
sender, RadFilterApplyExpressionsEventArgs e)
{
this
.hidReportFilter.Value =
new
ExpressionPersister().Save(((IStateManager)e.ExpressionRoot).SaveViewState());
var provider =
new
RadFilterSqlQueryProvider();
provider.ProcessGroup(e.ExpressionRoot);
RadGrid grid = (RadGrid)
this
.PlaceHolder1.FindControl(
"RadGrid1"
);
grid.MasterTableView.FilterExpression = provider.Result;
grid.Rebind();
}
Same error occurs on RadFilter1.FireApplyCommand(); in Page_Load.
0
Hi Robert,
Could you please try moving the code for setting the FilterContainerID of the RadFilter in the Page_Init event handler and see if it makes any difference? Setting it on Page_Load is too late for the control to be able to collect the desired information.
Kind regards,
Iana
the Telerik team
Could you please try moving the code for setting the FilterContainerID of the RadFilter in the Page_Init event handler and see if it makes any difference? Setting it on Page_Load is too late for the control to be able to collect the desired information.
Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Charlie
Top achievements
Rank 1
answered on 15 Jun 2011, 10:38 PM
I ran into this problem also. A few comments:
Why isn't this documented better? In the "Working with Expressions" section of the documentation, the code example does not indicate that you need to explicitly create field editors before creating expressions and adding them to the control. So you run into this error, and spend an hour figuring out why the control doesn't work.
The fact that you have to create a FieldEditor instance for each FilterExpression object, and map them by FieldName (what??), is just odd design. Why isn't the FieldEditor created in the FilterExpression object constructor? If it can't create one internally, a FilterExpression constructor should at least require a FieldEditor object so it's clear that you need to provide one.
I'm finding this control rather under designed.
Why isn't this documented better? In the "Working with Expressions" section of the documentation, the code example does not indicate that you need to explicitly create field editors before creating expressions and adding them to the control. So you run into this error, and spend an hour figuring out why the control doesn't work.
The fact that you have to create a FieldEditor instance for each FilterExpression object, and map them by FieldName (what??), is just odd design. Why isn't the FieldEditor created in the FilterExpression object constructor? If it can't create one internally, a FilterExpression constructor should at least require a FieldEditor object so it's clear that you need to provide one.
I'm finding this control rather under designed.
0
Hello Charlie,
I will forward your feedback to our developers and to our documentation team so they describe the case better.
All the best,
Iana
the Telerik team
I will forward your feedback to our developers and to our documentation team so they describe the case better.
All the best,
Iana
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.