I have Radgrid in which I am showing the data.
whenever there is a postback I am showing a loding panel with the help of
RadAjaxManager and RadAjaxLoadingPanel.
There is a facility to filter the Grid. After applying the filters, if there are no records for the filter criteria, I am making the Grid visible false. but after that if I apply new filter and make a postback, it throws the following error. As long as there are records in Grid and it is visible, I can apply filters and it works fine. But if there are no records for the filter criteria and I hide the Grid, it does not work for the next time even if I make the Grid Visble true. It throws the following exception. Please suggest.
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
My code is as below.
protected void Page_Load(object sender, EventArgs e)
{
pnlError.Visible = false;
setControlsVisibility(true);
}
protected void btnFilterResults_Click1(object sender, ImageClickEventArgs e)
{
FilterGrid();
}
void FilterGrid()
{
IsTopCommandCreated = false;
// Sites = All, ToDate & FromDate are selected
if (RadComboBoxSites.SelectedIndex == 0 && ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate != null)
{
RadGrid1.MasterTableView.FilterExpression = "(([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\')"
+ " AND " + "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\'))";
}
// Sites = All, ToDate = selected, FromDate = NULL
else if (RadComboBoxSites.SelectedIndex == 0 && ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate == null)
{
RadGrid1.MasterTableView.FilterExpression = "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\')";
}
// Sites = All, ToDate = NULL, FromDate = selected
else if (RadComboBoxSites.SelectedIndex == 0 && ToDatePicker.SelectedDate == null && FromDatePicker.SelectedDate != null)
{
RadGrid1.MasterTableView.FilterExpression = "([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\')";
}
// Sites = Specific Site, ToDate & FromDate are selected
else if (RadComboBoxSites.SelectedIndex != 0 && ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate != null)
{
RadGrid1.MasterTableView.FilterExpression = "(([SiteName] LIKE \'%" + RadComboBoxSites.SelectedItem.Text + "%\') "
+ " AND " + "([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\')"
+ " AND " + "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\'))";
}
// Sites = Specific Site, ToDate = selected, FromDate = NULL
else if (RadComboBoxSites.SelectedIndex != 0 && ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate == null)
{
RadGrid1.MasterTableView.FilterExpression = "(([SiteName] LIKE \'%" + RadComboBoxSites.SelectedItem.Text + "%\') "
+ " AND " + "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\'))";
}
// Sites = Specific Site, ToDate = NULL, FromDate = selected
else if (RadComboBoxSites.SelectedIndex != 0 && ToDatePicker.SelectedDate == null && FromDatePicker.SelectedDate != null)
{
RadGrid1.MasterTableView.FilterExpression = "(([SiteName] LIKE \'%" + RadComboBoxSites.SelectedItem.Text + "%\') "
+ " AND " + "([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\'))";
}
// Sites = Specific Site, ToDate & FromDate are NULL
else if (RadComboBoxSites.SelectedIndex != 0 && ToDatePicker.SelectedDate == null && FromDatePicker.SelectedDate == null)
{
RadGrid1.MasterTableView.FilterExpression = "([SiteName] LIKE \'%" + RadComboBoxSites.SelectedItem.Text + "%\')";
}
// Otherwise display open invoices for all regional sites.
else
{
RadGrid1.MasterTableView.FilterExpression = "";
}
GridColumn columnSite = RadGrid1.MasterTableView.GetColumnSafe("SiteName");
GridColumn columnDateDue = RadGrid1.MasterTableView.GetColumnSafe("DateDue");
// Sites = Specific Site
if (RadComboBoxSites.SelectedIndex != 0)
{
columnSite.CurrentFilterFunction = GridKnownFunction.Contains;
columnSite.CurrentFilterValue = RadComboBoxSites.SelectedItem.Text;
}
// ToDate & FromDate are selected
if (ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate != null)
{
columnDateDue.CurrentFilterFunction = GridKnownFunction.Between;
columnDateDue.CurrentFilterValue = "(([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\')"
+ " AND " + "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\'))";
}
// ToDate = selected, FromDate = NULL
else if (ToDatePicker.SelectedDate != null && FromDatePicker.SelectedDate == null)
{
columnDateDue.CurrentFilterFunction = GridKnownFunction.LessThanOrEqualTo;
columnDateDue.CurrentFilterValue = "([DateDue] <= \'" + ToDatePicker.SelectedDate.ToString() + "\')";
}
// ToDate = NULL, FromDate = selected
else if (ToDatePicker.SelectedDate == null && FromDatePicker.SelectedDate != null)
{
columnDateDue.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
columnDateDue.CurrentFilterValue = "([DateDue] >= \'" + FromDatePicker.SelectedDate.ToString() + "\')";
}
RadGrid1.DataSourceID = "InvoiceDataSource";
RadGrid1.MasterTableView.Rebind();
}
/// <
summary
>
/// Set the visibility of the main datatable, the filtering and the forwardtoColleague sections
/// </
summary
>
/// <
param
name
=
"visibility"
></
param
>
void setControlsVisibility(bool visibility)
{
var controls = new Control[] { RadGrid1, pnlFilter, ForwardToColleagueMain };
foreach (var c in controls)
{
if (c != null)
{
c.Visible = visibility;
}
}
}