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

RadGrid issue: Invalid postback or callback argument

1 Answer 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandy Rani
Top achievements
Rank 1
Sandy Rani asked on 31 Aug 2010, 11:46 AM

 

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;
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 02 Sep 2010, 02:29 PM
Hi Sandy,

Please note that adding invisible control, into the RadAjaxManager settings is not supported scenario. The controls which are Ajax initiators or updated controls should be always visible on the page. I would suggest you to wrap the RadGrid into always visible container (for ex. asp Panel) and add this container into the RadAjaxSettings.
Test this approach and let me know if it makes any difference.


Sincerely yours,
Maria Ilieva
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
Grid
Asked by
Sandy Rani
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or