Hello Telerik,
I have an .ASPX page with a RadGrid that has AllowFilteringByColumn="true". When I filter on multiple columns, I get the expected resulting records.
My problem is when I put the same RadGrid in a user control and embed this user control in another .ASPX page.
When I filter on one column, it works fine. But when I filter on another column, it always overrides the previous filter. Filtering on multiple columns does not work. I've used Session variables to store the FilterExpression and tried applying it at various points but have not been successful.
I've exhausted so many hours trying to make this work, but to no avail.
Would you please create a working sample project (VB preferred) that shows this is at all possible?
Many thanks as always.
Virgil
14 Answers, 1 is accepted
Possible problem can be broken or not correctly loaded ViewState. In this case you loose all previous actions, and only latest filter remains.
You can confirm that if the filter disappears if you perform another operation like sorting or paging.
If this is the problem, you may want to check if your grid and the user control have ClientIdMode="AutoID" which is necessarily for grid to operate correctly.
If you load the user control dynamically, make sure it is loaded no later than Page_Load.
Regards,
Vasil
Telerik by Progress
Hi Vasil,
It's confirmed that the filter disappears when sorting or paging.
Used ClientIDMode="AutoId" but still the same issue.
Any chance you guys can create a working sample project (preferably VB)?
Thanks,
Virgil
Hi Vasil,
Here is a new development.
The problem only happens when the user control is dynamically loaded. And I made sure that the loading is done during Page_Load.
Kindly provide a working sample project with a page that dynamically loads a user control that has a RadGrid in it.
Thanks,
Virgil
I am attaching a VB sample, based on the default VS template. It contains RadGrid inside an UserControl loaded dynamically during PageLoad inside a content page.
Regards,
Vasil
Telerik by Progress
Hi Vasil,
Please see attached project. I have an .ASPX file with a built in RadGrid and a user control (.ASCX) with its own RadGrid and the user control is dynamically loaded into the .ASPX file.
Both grids cannot process multiple column filters. Can you please look into it and see what I'm missing or doing wrong.
By the way, Have a Merry Christmas and a Happy New Year 2017.
Thanks again.
Virgil
===================
web.config
<?xml version="1.0"?><!-- For more information on how to configure your ASP.NET application, please visit --><configuration> <system.web> <compilation debug="true" strict="false" explicit="true" targetFramework="4.6" /> <httpRuntime targetFramework="4.6" /> <pages controlRenderingCompatibilityVersion="4.0"> <controls> <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/> </controls> </pages> <httpHandlers> <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/> </httpHandlers> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"/> <handlers> <remove name="Telerik_Web_UI_WebResource_axd"/> <add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode"/> </handlers> <security> <requestFiltering> <requestLimits maxAllowedContentLength="41943040"/> </requestFiltering> </security> </system.webServer></configuration>
Site.master
<%@ Master Language="VB" AutoEventWireup="true" CodeFile="Site.master.vb" Inherits="SiteMaster" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><!DOCTYPE html><html lang="en"><head runat="server"> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title><%: Page.Title %> - My ASP.NET Application</title></head><body> <form runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> <div class="container body-content"> <asp:ContentPlaceHolder ID="MainContent" runat="server"> </asp:ContentPlaceHolder> <hr /> <footer> <p>© <%: DateTime.Now.Year %> - My ASP.NET Application</p> </footer> </div> </form></body></html>
Site.master.vb
Imports System.Collections.GenericImports System.Security.ClaimsImports System.Security.PrincipalImports System.WebImports System.Web.SecurityImports System.Web.UIImports System.Web.UI.WebControlsPublic Partial Class SiteMaster Inherits MasterPage Private Const AntiXsrfTokenKey As String = "__AntiXsrfToken" Private Const AntiXsrfUserNameKey As String = "__AntiXsrfUserName" Private _antiXsrfTokenValue As String Protected Sub Page_Init(sender As Object, e As EventArgs) ' The code below helps to protect against XSRF attacks Dim requestCookie = Request.Cookies(AntiXsrfTokenKey) Dim requestCookieGuidValue As Guid If requestCookie IsNot Nothing AndAlso Guid.TryParse(requestCookie.Value, requestCookieGuidValue) Then ' Use the Anti-XSRF token from the cookie _antiXsrfTokenValue = requestCookie.Value Page.ViewStateUserKey = _antiXsrfTokenValue Else ' Generate a new Anti-XSRF token and save to the cookie _antiXsrfTokenValue = Guid.NewGuid().ToString("N") Page.ViewStateUserKey = _antiXsrfTokenValue Dim responseCookie = New HttpCookie(AntiXsrfTokenKey) With { .HttpOnly = True, .Value = _antiXsrfTokenValue } If FormsAuthentication.RequireSSL AndAlso Request.IsSecureConnection Then responseCookie.Secure = True End If Response.Cookies.[Set](responseCookie) End If AddHandler Page.PreLoad, AddressOf master_Page_PreLoad End Sub Protected Sub master_Page_PreLoad(sender As Object, e As EventArgs) If Not IsPostBack Then ' Set Anti-XSRF token ViewState(AntiXsrfTokenKey) = Page.ViewStateUserKey ViewState(AntiXsrfUserNameKey) = If(Context.User.Identity.Name, [String].Empty) Else ' Validate the Anti-XSRF token If DirectCast(ViewState(AntiXsrfTokenKey), String) <> _antiXsrfTokenValue OrElse DirectCast(ViewState(AntiXsrfUserNameKey), String) <> (If(Context.User.Identity.Name, [String].Empty)) Then Throw New InvalidOperationException("Validation of Anti-XSRF token failed.") End If End If End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) End Sub Protected Sub Unnamed_LoggingOut(sender As Object, e As LoginCancelEventArgs) 'Context.GetOwinContext().Authentication.SignOut() End SubEnd Class
Default.aspx
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="true"> </telerik:RadAjaxManager> <telerik:RadGrid PageSize="3" AllowPaging="true" AllowFilteringByColumn="true" AllowSorting="true" MasterTableView-EditFormSettings-EditColumn-AutoPostBackOnFilter="true" ID="MyGrid_InASPX" runat="server" OnNeedDataSource="MyGrid_InASPX_NeedDataSource" AutoGenerateColumns="false" MasterTableView-CommandItemDisplay="Top" ClientIDMode="AutoID"> <MasterTableView DataKeyNames="RowNumber" AllowMultiColumnSorting="true" Caption="<strong><big>RadGrid in .ASPX</strong></big>"> <Columns> <telerik:GridBoundColumn HeaderText="RowNumber" DataField="RowNumber" UniqueName="RowNumber" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Size" DataField="Size" UniqueName="Size" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Quantity" DataField="Quantity" UniqueName="Quantity" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Unit" DataField="Unit" UniqueName="Unit" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Duration" DataField="Duration" UniqueName="Duration" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="DurationType" DataField="DurationType" UniqueName="DurationType" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" UniqueName="Amount" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid> <BR/> <asp:PlaceHolder runat="server" ID="myPlaceHolder" ></asp:PlaceHolder> </asp:Content>
Default.aspx.vb
Imports System.DataImports Telerik.Web.UIPartial Class _Default Inherits Page Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim newControl As UserControl = LoadControl("~/WebUserControl1.ascx") newControl.ClientIDMode = ClientIDMode.AutoID Me.myPlaceHolder.Controls.Add(newControl) If Not Page.IsPostBack Then MyGrid_InASPX.DataBind() End If End Sub Protected Sub MyGrid_InASPX_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Dim grid = DirectCast(sender, RadGrid) ' ' Here we create a DataTable with a few columns. ' ' Create Datatable to store all colums Dim dt As New DataTable() Dim dr As DataRow = Nothing dt.Columns.Add(New DataColumn("RowNumber", GetType(String))) dt.Columns.Add(New DataColumn("Size", GetType(String))) dt.Columns.Add(New DataColumn("Description", GetType(String))) dt.Columns.Add(New DataColumn("Quantity", GetType(String))) dt.Columns.Add(New DataColumn("Unit", GetType(String))) dt.Columns.Add(New DataColumn("Duration", GetType(String))) dt.Columns.Add(New DataColumn("DurationType", GetType(String))) dt.Columns.Add(New DataColumn("Amount", GetType(String))) dr = dt.NewRow() dr("RowNumber") = 1 dr("Size") = "Size 111 AAA" dr("Description") = "Description 222 AAA" dr("Quantity") = "Quantity 333 AAA" dr("Unit") = "Unit 444 AAA" dr("Duration") = "Duration 555 AAA" dr("DurationType") = "Type 666 AAA" dr("Amount") = "Amount 777 AAA" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 2 dr("Size") = "Size 111 BBB" dr("Description") = "Description 222 BBB" dr("Quantity") = "Quantity 333 BBB" dr("Unit") = "Unit 444 BBB" dr("Duration") = "Duration 555 BBB" dr("DurationType") = "Type 666 BBB" dr("Amount") = "Amount 777 BBB" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 3 dr("Size") = "Size 111 CCC" dr("Description") = "Description 222 CCC" dr("Quantity") = "Quantity 333 CCC" dr("Unit") = "Unit 444 CCC" dr("Duration") = "Duration 555 CCC" dr("DurationType") = "Type 666 CCC" dr("Amount") = "Amount 777 CCC" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 4 dr("Size") = "Size 111 DDD" dr("Description") = "Description 222 DDD" dr("Quantity") = "Quantity 333 DDD" dr("Unit") = "Unit 444 DDD" dr("Duration") = "Duration 555 DDD" dr("DurationType") = "Type 666 DDD" dr("Amount") = "Amount 777 DDD" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 5 dr("Size") = "Size 111 EEE" dr("Description") = "Description 222 EEE" dr("Quantity") = "Quantity 333 EEE" dr("Unit") = "Unit 444 EEE" dr("Duration") = "Duration 555 EEE" dr("DurationType") = "Type 666 EEE" dr("Amount") = "Amount 777 EEE" dt.Rows.Add(dr) grid.DataSource = dt End SubEnd Class
WebUserControl1.ascx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl1.ascx.vb" Inherits="WebUserControl1" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><telerik:RadGrid PageSize="3" AllowPaging="true" AllowFilteringByColumn="true" AllowSorting="true" MasterTableView-EditFormSettings-EditColumn-AutoPostBackOnFilter="true" ID="MyGrid" runat="server" OnNeedDataSource="MyGrid_NeedDataSource" AutoGenerateColumns="false" MasterTableView-CommandItemDisplay="Top" ClientIDMode="AutoID"> <MasterTableView DataKeyNames="RowNumber" AllowMultiColumnSorting="true" Caption="<strong><big>RadGrid in User Control (.ASCX) dynamically loaded </strong> </big>"> <Columns> <telerik:GridBoundColumn HeaderText="RowNumber" DataField="RowNumber" UniqueName="RowNumber" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Size" DataField="Size" UniqueName="Size" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Description" DataField="Description" UniqueName="Description" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Quantity" DataField="Quantity" UniqueName="Quantity" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Unit" DataField="Unit" UniqueName="Unit" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Duration" DataField="Duration" UniqueName="Duration" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="DurationType" DataField="DurationType" UniqueName="DurationType" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" UniqueName="Amount" AutoPostBackOnFilter="true" ShowFilterIcon="false" ReadOnly="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>
WebUserControl1.ascx.vb
Imports System.DataImports Telerik.Web.UIPartial Class WebUserControl1 Inherits System.Web.UI.UserControl Protected Sub MyGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Dim grid = DirectCast(sender, RadGrid) ' ' Here we create a DataTable with a few columns. ' ' Create Datatable to store all colums Dim dt As New DataTable() Dim dr As DataRow = Nothing dt.Columns.Add(New DataColumn("RowNumber", GetType(String))) dt.Columns.Add(New DataColumn("Size", GetType(String))) dt.Columns.Add(New DataColumn("Description", GetType(String))) dt.Columns.Add(New DataColumn("Quantity", GetType(String))) dt.Columns.Add(New DataColumn("Unit", GetType(String))) dt.Columns.Add(New DataColumn("Duration", GetType(String))) dt.Columns.Add(New DataColumn("DurationType", GetType(String))) dt.Columns.Add(New DataColumn("Amount", GetType(String))) dr = dt.NewRow() dr("RowNumber") = 1 dr("Size") = "Size 111 AAA" dr("Description") = "Description 222 AAA" dr("Quantity") = "Quantity 333 AAA" dr("Unit") = "Unit 444 AAA" dr("Duration") = "Duration 555 AAA" dr("DurationType") = "Type 666 AAA" dr("Amount") = "Amount 777 AAA" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 2 dr("Size") = "Size 111 BBB" dr("Description") = "Description 222 BBB" dr("Quantity") = "Quantity 333 BBB" dr("Unit") = "Unit 444 BBB" dr("Duration") = "Duration 555 BBB" dr("DurationType") = "Type 666 BBB" dr("Amount") = "Amount 777 BBB" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 3 dr("Size") = "Size 111 CCC" dr("Description") = "Description 222 CCC" dr("Quantity") = "Quantity 333 CCC" dr("Unit") = "Unit 444 CCC" dr("Duration") = "Duration 555 CCC" dr("DurationType") = "Type 666 CCC" dr("Amount") = "Amount 777 CCC" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 4 dr("Size") = "Size 111 DDD" dr("Description") = "Description 222 DDD" dr("Quantity") = "Quantity 333 DDD" dr("Unit") = "Unit 444 DDD" dr("Duration") = "Duration 555 DDD" dr("DurationType") = "Type 666 DDD" dr("Amount") = "Amount 777 DDD" dt.Rows.Add(dr) dr = dt.NewRow() dr("RowNumber") = 5 dr("Size") = "Size 111 EEE" dr("Description") = "Description 222 EEE" dr("Quantity") = "Quantity 333 EEE" dr("Unit") = "Unit 444 EEE" dr("Duration") = "Duration 555 EEE" dr("DurationType") = "Type 666 EEE" dr("Amount") = "Amount 777 EEE" dt.Rows.Add(dr) grid.DataSource = dt End Sub Private Sub WebUserControl1_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then MyGrid.DataBind() End If End SubEnd ClassYou should load the control conditionally, since you do it on Page_Load. Currently when you load it second time, it clears the old view-state.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Page.FindControl("myUC") = Nothing Then Dim myControl As Control = Me.LoadControl("gridUC.ascx") myControl.ID = "myUC" Me.Panel1.Controls.Add(myControl) End IfEnd SubRegards,
Vasil
Telerik by Progress
Thanks, but still no luck Vasil.
Would you be able to create a project out of the above source codes I provided and attach it back as a .ZIP file when you have found the fix?
Thanks once again.
No, but if you send us such a project, instead of pasting parts of the code, I would try fix it.
Regards,
Vasil
Telerik by Progress
Hi Vasil,
How do you attach a .ZIP file? I would gladly send the whole project to you but I am not able to attach a .ZIP file. Which is why I just copy & pasted the relevant files (in my previous post) which are by the way complete source codes not merely parts of them:
- web.config
- Site.master
- Site.master.vb
- Default.aspx
- Default.aspx.vb
- WebUserControl1.ascx
- WebUserControl1.ascx.vb
Actually, I used the project in your SimpleVB.zip and just modified the Default.aspx, Default.aspx.vb, WebUserControl1.ascx and WebUserControl1.ascx.vb files.
Thanks again.
Virgil
I did replaced the code from your post into the sample page, but it works correctly. So it must be something else in your page that causing the ViewState issue. Please see the project and compare it with yours.
If you like to submit archive, you can open a support ticket and attack it there.
Regards,
Vasil
Telerik by Progress
Thanks Vasil, but I still couldn't make it work.
When you say it's working correctly, do you mean you can use multiple filters on both grids and the filter works properly?
Anyway, I will attach the project in a Support Ticket as you have advised.
Thank you again.
Yes, they both work the same from what I see, but maybe there is something that I am missing. Check this video and let me know what is different when you run the page.
https://www.screencast.com/t/0QcRtFnid
edit: I saw you was not using the latest version, my bad didn't guessed that.
Regards,
Vasil
Telerik by Progress
I submitted a ticket as you advised and Konstantin suggested to upgrade to the latest Telerik Version.
Apparently it was an identified bug in the version that I was using.
It is now working.
Thank you.