New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Programmatic Creation

There are two options for creating adding the RadFilter field editors dynamically - on Page_Load and Page_Init.

Creating the field editors on Page_Load

When creating a field editor in the Page_Load event handler, it should be added to the FieldEditors collection first, before its values are set. This is important because no ViewState is managed for the editor before it has been added. Also, be sure to check that IsPostBack is false. Otherwise, you will end up adding the same editors to the RadFilter multiple times.

ASPNET
<telerik:RadFilter RenderMode="Lightweight" runat="server" ID="RadFilter1" FilterContainerID="SqlDataSource1" ExpressionPreviewPosition="Bottom">
</telerik:RadFilter>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="Select OrderID, OrderDate, ShipVia, ShipName, ShipAddress, ShipCity, ShipCountry FROM Orders">
</asp:SqlDataSource>

Creating the field editors on Page_Init

When creating a field editor in the Page_Init event handler, it should be added to the FieldEditors collection after its attributes are set. No ViewState is required for the editor to be persisted as it is recreated on each page initialization.

ASPNET
<telerik:RadFilter RenderMode="Lightweight" runat="server" ID="RadFilter1" FilterContainerID="SqlDataSource1" ExpressionPreviewPosition="Bottom">
</telerik:RadFilter>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="Select OrderID, OrderDate, ShipVia, ShipName, ShipAddress, ShipCity, ShipCountry FROM Orders">
</asp:SqlDataSource>