This is a migrated thread and some comments may be shown as answers.

Add RadFilterTextFieldEditor programmatically

4 Answers 98 Views
Filter
This is a migrated thread and some comments may be shown as answers.
dimrud
Top achievements
Rank 1
dimrud asked on 09 Sep 2010, 08:34 PM
Hello,
I am trying to add RadFilterTextFieldEditor programmatically. It works fine BUT after any action with the field I am getting an error

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

ASP code

   <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="LoadingPanel1" EnableAJAX="true" >
             
                <telerik:RadFilter  runat="server" ID="RadFilter1" ExpressionPreviewPosition="Bottom" Enabled="false" RegisterWithScriptManager="true" EnableEmbeddedScripts="true"  EnableViewState ="true"  >
                </telerik:RadFilter>
            </telerik:RadAjaxPanel>

C# code
   RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
            editor.FieldName = "field1";
            editor.DataType = typeof(string);
            editor.DisplayName = "Field 1";
            RadFilter1.FieldEditors.Add(editor);
            RadFilterTextFieldEditor editor1 = new RadFilterTextFieldEditor();
            editor1.FieldName = "field2";
            editor1.DataType = typeof(string);
            editor1.DisplayName = "Field 2";
            RadFilter1.FieldEditors.Add(editor1);

Please help !!!

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 10 Sep 2010, 01:41 PM
Hello dimrud,

Is the C# code pasted placed in the Page_Load event handler? Try modifying it as below and see if it makes any difference:

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
RadFilter1.FieldEditors.Add(editor1);
editor.FieldName = "field1";
editor.DataType = typeof(string);
editor.DisplayName = "Field 1";
RadFilter1.FieldEditors.Add(editor);
RadFilterTextFieldEditor editor1 = new RadFilterTextFieldEditor();
editor1.FieldName = "field2";
editor1.DataType = typeof(string);
editor1.DisplayName = "Field 2";


Sincerely yours,
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
dimrud
Top achievements
Rank 1
answered on 10 Sep 2010, 02:13 PM
Dear Lana,
You changed place of 1line
And now it works fine. Is it not strange behavior of the code ?
Anyway, Thank you very much.

My code :

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
            editor.FieldName = "field1";
            editor.DataType = typeof(string);
            editor.DisplayName = "Field 1";
            RadFilter1.FieldEditors.Add(editor);
To :

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
RadFilter1.FieldEditors.Add(editor1);
editor.FieldName = "field1";
editor.DataType = typeof(string);
editor.DisplayName = "Field 1";

0
Bruce
Top achievements
Rank 1
answered on 06 Nov 2010, 07:38 AM
It does not make sense to me. The new code should give a compiling error because editor1 is not defined yet when it is added to the editor collection.

Can someone explain this?

Thanks
0
Iana Tsolova
Telerik team
answered on 09 Nov 2010, 03:03 PM
Hello Bruce,

Please excuse me for the misleading code. Here is the proper one:

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor(); 
RadFilter1.FieldEditors.Add(editor); 
editor.FieldName = "field1"
editor.DataType = typeof(string); 
editor.DisplayName = "Field 1"
  
RadFilterTextFieldEditor editor1 = new RadFilterTextFieldEditor(); 
RadFilter1.FieldEditors.Add(editor1); 
editor1.FieldName = "field2"
editor1.DataType = typeof(string); 
editor1.DisplayName = "Field 2";

Note that this code is to be used when adding the editors on Page_Load.
In case you are adding them on Page_Init, here is the code one should use:

RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();   
editor.FieldName = "field1";  
editor.DataType = typeof(string);  
editor.DisplayName = "Field 1";
RadFilter1.FieldEditors.Add(editor);
    
RadFilterTextFieldEditor editor1 = new RadFilterTextFieldEditor();  
editor1.FieldName = "field2";  
editor1.DataType = typeof(string);  
editor1.DisplayName = "Field 2";
RadFilter1.FieldEditors.Add(editor1);

Note that on Page_Init, the editor properties are first set, and then it is added to the FieldEditors collection. And it is opposite when editors are created on Page_Load: the editor is first added to the FieldEditors collection and then its properties are set. Also on Page_Load editors are added only on initial load (in if(!IsPostBack) statement) whereas on Page_Init are added on each postback.

I hope this makes it all clear.

All the best,
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
Tags
Filter
Asked by
dimrud
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
dimrud
Top achievements
Rank 1
Bruce
Top achievements
Rank 1
Share this question
or