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

Error exporting radgrid from radwindow

1 Answer 108 Views
Window
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 18 Jul 2011, 09:31 PM
Hi all,

I have a default page which is ajax enabled. From here I open a report.aspx page which is loaded into a radwindow. The report.aspx page is just a grid with data. When I try and export this data I get the error:

"

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


"

I'm not sure why I'm getting this. Can someone please help me find the solution? Code below: Thanks!

Report.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="quick_transaction_popup.aspx.cs" Inherits="OnTime.OnTime_Reports.Visitors.quick_transaction_popup" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
    <telerik:RadScriptManager ID="Report_ScriptManager" runat="server" />
 
            <h3>
                <asp:Literal ID="Literal_View1_Title" runat="server" Text="Transactions: Quick Report - "></asp:Literal>
            </h3>
 
                <asp:PlaceHolder ID="PlaceHolder_Report_SQL" runat="server">
                    <asp:SqlDataSource ID="SqlDataSource_Report" runat="server">
                    </asp:SqlDataSource>
                </asp:PlaceHolder>
 
            <telerik:RadGrid ID="RadGrid_Report" runat="server" AutoGenerateColumns="false"
            AllowMultiRowSelection="false" AllowAutomaticInserts="false"
            GridLines="None" CellPadding="0" AllowSorting="false" Skin="Outlook"
            ItemStyle-VerticalAlign="Top"
            OnExcelMLExportRowCreated="RadGrid_Report_ExcelMLExportRowCreated" Width="100%"
            >
 
                <ExportSettings HideStructureColumns="true" ExportOnlyData="true" FileName="Visitor_TQR" OpenInNewWindow="true"
                 IgnorePaging="true">
                    <Excel Format="ExcelML" />
                </ExportSettings>
 
                <MasterTableView Width="100%" CommandItemDisplay="Top" GridLines="None" AllowAutomaticInserts="false">
 
                <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToWordButton="false" ShowExportToExcelButton="true"
                ShowExportToCsvButton="false" ShowRefreshButton="false"/>
                 
                    <Columns>
 
                         <telerik:GridBoundColumn UniqueName="Report_Logs_DateTime" DataField="Visitor_Logs_DateTime"
                         HeaderText="Time" HeaderStyle-Width="33%" Visible="true" ItemStyle-VerticalAlign="Top"/>
 
                         <telerik:GridBoundColumn UniqueName="Report_Transaction_Type" DataField="Function_Key_Description"
                         HeaderText="Transaction Type" HeaderStyle-Width="33%" Visible="true" ItemStyle-VerticalAlign="Top"/>
 
                         <telerik:GridBoundColumn UniqueName="Report_UserName" DataField="Visitor_UserName"
                         HeaderText="Visitor" HeaderStyle-Width="33%" Visible="true" ItemStyle-VerticalAlign="Top"/>
 
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="false" />
                </ClientSettings>
            </telerik:RadGrid>
 
 
     
    </div>
    </form>
</body>
</html>


Report.aspx.cs
protected void Page_Load(object sender, EventArgs e)
        {
            //Register Javascript for Export Buttons
            string script2 = "function onRequestStart(sender, args)" +
                "{" +
                    "if (args.get_eventTarget().indexOf(\"ExportToExcelButton\") >= 0 ||" +
                    "args.get_eventTarget().indexOf(\"ExportToWordButton\") >= 0 ||" +
                    "args.get_eventTarget().indexOf(\"ExportToCsvButton\") >= 0)" +
                "{" +
                    "args.set_enableAjax(false);" +
                "}" +
                "}";
 
            //I've tried commenting and UN-commenting this line with no luck!
            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Report_RadGrid_Ajax_Disable", script2, true);
 
            Display_Report_RadGrid();
 
        }
 
        protected void Display_Report_RadGrid()
        {
 
            //Populate Rad Grid
            SqlDataSource_Report = new SQL_Data_Source().getSQLDataSource();
            SqlDataSource_Report.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            SqlDataSource_Report.SelectCommand = SQL_Customer_Connection.Product_Name + "_rp_Visitor_TQR";
 
            SqlDataSource_Report.SelectParameters.Add("Param_Customer_ID_Ref", TypeCode.String, (string)Session["User_Belongs_To_Customer_Ref_ID"]);
            SqlDataSource_Report.SelectParameters.Add("Param_Company_ID_Ref", TypeCode.String, (string)Session["User_Belongs_To_Company_Ref_ID"]);
 
            SqlDataSource_Report.SelectParameters.Add("Param_Visitor_Auto_ID_Ref", TypeCode.Int32, "22");
            SqlDataSource_Report.SelectParameters.Add("Param_Transaction_Types", TypeCode.String, "0,1,2,3,4,5,6,7,8");
 
            SqlDataSource_Report.SelectParameters.Add("Param_Start_Date", TypeCode.DateTime, "2011-01-01");
            SqlDataSource_Report.SelectParameters.Add("Param_End_Date", TypeCode.DateTime, "2012-01-01");
 
            RadGrid_Report.DataSource = SqlDataSource_Report;
            RadGrid_Report.Rebind();
        }
 
 
        bool ExcelML_isConfigured = false;
 
        protected void RadGrid_Report_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
        {
            if (e.RowType == GridExportExcelMLRowType.DataRow)
            {
                //Add custom styles to the desired cells
                 
 
                if (!ExcelML_isConfigured)
                {
                    //Set Worksheet name
                    e.Worksheet.Name = "Visitor_TQR";
 
                    //Set Column widths
                    foreach (ColumnElement column in e.Worksheet.Table.Columns)
                    {
                        switch (e.Worksheet.Table.Columns.IndexOf(column))
                        {
                            case 1:
                                column.Width = Unit.Point(100);
                                break;
                            case 2:
                                column.Width = Unit.Point(150);
                                break;
                            case 3:
                                column.Width = Unit.Point(150);
                                break;
                        }
                    }
 
                    //Set Page options
                    PageSetupElement pageSetup = e.Worksheet.WorksheetOptions.PageSetup;
                    pageSetup.PageLayoutElement.IsCenteredVertical = true;
                    pageSetup.PageLayoutElement.IsCenteredHorizontal = true;
                    pageSetup.PageMarginsElement.Left = 0.5;
                    pageSetup.PageMarginsElement.Top = 0.5;
                    pageSetup.PageMarginsElement.Right = 0.5;
                    pageSetup.PageMarginsElement.Bottom = 0.5;
                    //pageSetup.PageLayoutElement.PageOrientation = PageOrientationType.Landscape;
 
                    //Freeze panes
                    e.Worksheet.WorksheetOptions.AllowFreezePanes = true;
                    e.Worksheet.WorksheetOptions.LeftColumnRightPaneNumber = 1;
                    e.Worksheet.WorksheetOptions.TopRowBottomPaneNumber = 1;
                    e.Worksheet.WorksheetOptions.SplitHorizontalOffset = 1;
                    e.Worksheet.WorksheetOptions.SplitVerticalOffest = 1;
 
                    e.Worksheet.WorksheetOptions.ActivePane = 2;
                    ExcelML_isConfigured = true;
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 20 Jul 2011, 12:25 PM
Hello Sunil,

You will get this error even if you do not put this page in a RadWindow. Its origin is the way you bind the grid - to use ExcelML export you need to use advanced databinding and not a datasource popupated on PageLoad, as explained in the following help article: http://www.telerik.com/help/aspnet-ajax/grid-excelml-export.html.

That being said I ran your code with the NeedDataSource event (I used a dummy datasource since I do not have your actual one) and things seem to be working fine: http://screencast.com/t/b3UESqi0. You can find attached my test page as a reference.


Kind regards,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Window
Asked by
Sunil
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or