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

[Solved] ExportToCSV give error For RefquiredFieldValidator

3 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 12 Aug 2009, 06:31 AM
Hi,

I have a RadToolBarButton List, Export to Excel, Word, Csv and Pdf. I try to export the data from RadGrid, there are no issue for all the button except CSV. My Grid have one column with RadDateTimePicker and RequiredFieldValidator. When I click Csv button, I got the following error. I have already added CauseValidation = "false" but still no changes.

Unable to find control id 'radprocessLogEffectiveStartDate' referenced by the 'ControlToValidate' property of 'RequiredFieldValidator1'.

radGrid.ExportSettings.ExportOnlyData =

false;

 

 

radGrid.MasterTableView.ExportToCSV();



Thanks,
Alex

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Aug 2009, 07:48 AM
Hello Alex,

Could you post your code so we can reproduce this behavior locally? Please use the "Format Code Block" button as illustrated on the attached screenshot.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Alex
Top achievements
Rank 1
answered on 12 Aug 2009, 08:27 AM
<telerik:radtoolbar id="RadToolBar1" runat="server" skin="Office2007"  CausesValidation="false" 
                    width="30%" onbuttonclick="rtbButton_ButtonClick"
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                    <Items> 
                        <telerik:RadToolBarButton ImageUrl="../App_Themes/Default/Images/Word.jpg" runat="server" Text="Word" CausesValidation="false"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton ImageUrl="../App_Themes/Default/Images/Excel.jpg" runat="server" Text="Excel" CausesValidation="false"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton ImageUrl="../App_Themes/Default/Images/CSV.jpg" runat="server" Text="Csv" CausesValidation="false"
                        </telerik:RadToolBarButton> 
                        <telerik:RadToolBarButton ImageUrl="../App_Themes/Default/Images/Pdf.jpg" runat="server" Text="Pdf" CausesValidation="false"
                        </telerik:RadToolBarButton> 
                         
                    </Items> 
                </telerik:radtoolbar> 
<telerik:RadGrid ID="rgProcess"  runat="server" AllowPaging="True" AllowSorting="True" 
                            AutoGenerateColumns="False" Skin="Office2007" 
                            Width="97%" ShowStatusBar="True"  
                            ShowFooter="True"  
                            AllowMultiRowSelection="True" CellPadding="1" CellSpacing="1"  
                            onneeddatasource="rgProcess_NeedDataSource" ValidationSettings-EnableValidation ="true" 
                            onitemdatabound="rgProcess_ItemDataBound">                              
                            <PagerStyle Mode="NextPrevAndNumeric" /> 
                            <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID"
                                <Columns> 
                                    <telerik:GridBoundColumn DataField="Process.FCCOffice.Name" HeaderText="FCC Office" UniqueName="FCCOfficeName" ReadOnly="true"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="Process.Application.Name" HeaderText="Application Name" UniqueName="ApplicationName" ReadOnly="true" Display="true"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Effective Start Date" UniqueName="processLogEffectiveStartDate"
                                    <ItemTemplate> 
                                        <telerik:RadDateTimePicker  ID="radprocessLogEffectiveStartDate" runat="server" />                                         
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Enabled="false" ControlToValidate="radprocessLogEffectiveStartDate" runat="server" ErrorMessage="Effective Date is invalid."></asp:RequiredFieldValidator> 
                                    </ItemTemplate> 
                                    </telerik:GridTemplateColumn>                                     
                                </Columns> 
                            </MasterTableView> 
                            <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true"
                                <Selecting AllowRowSelect="True" /> 
                            </ClientSettings> 
                            <FilterMenu EnableTheming="True"
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                            </FilterMenu> 
                        </telerik:RadGrid> 
protected void GridExport(Telerik.Web.UI.RadGrid radGrid, string fileName, string Format, DCCPP.BusinessEntities.Enums.PdfOrientationEnum pdfOrientation) 
        { 
            radGrid.ExportSettings.IgnorePaging = true
            radGrid.ExportSettings.OpenInNewWindow = true
            radGrid.ExportSettings.ExportOnlyData = true
            radGrid.MasterTableView.CurrentPageIndex = 0
            //radGrid.ItemStyle.Font.ClearDefaults(); 
            //radGrid.ItemStyle.Font.Names = new String[] { "Tahoma" };  //Times New Roman 
 
            GridColumn gridClientSelectColumn = radGrid.Columns.FindByUniqueNameSafe("Select"); 
            if (gridClientSelectColumn != null) gridClientSelectColumn.Visible = false
            //if (radGrid.MasterTableView.GetColumn("Select") != null) 
            //    radGrid.MasterTableView.GetColumn("Select").Visible = false; // Where 'Select' is the UninqueNAme of GridClientSelectColumn   
            GridColumn autoGeneratedEditcolumn = radGrid.Columns.FindByUniqueNameSafe("AutoGeneratedEditcolumn"); 
            if (autoGeneratedEditcolumn != null) autoGeneratedEditcolumn.Visible = false
            //radGrid.MasterTableView.GetColumn("AutoGeneratedEditcolumn").Visible = false
            radGrid.ExportSettings.FileName = fileName
 
            if (Format.Equals("Excel")) 
            { 
                radGrid.MasterTableView.ExportToExcel(); 
            } 
            else if (Format.Equals("Csv")) 
            { 
                radGrid.ExportSettings.ExportOnlyData = false
                 
                radGrid.MasterTableView.ExportToCSV(); 
 
            } 
            else if (Format.Equals("Pdf")) 
            { 
                if (pdfOrientation == DCCPP.BusinessEntities.Enums.PdfOrientationEnum.Landscape) 
                { 
                    radGrid.ExportSettings.Pdf.PageHeight = Unit.Parse("162mm"); 
                    radGrid.ExportSettings.Pdf.PageWidth = Unit.Parse("600mm"); 
                } 
                radGrid.MasterTableView.ExportToPdf(); 
            } 
            else if (Format.Equals("Word")) 
            { 
                radGrid.MasterTableView.ExportToWord(); 
            } 
        } 
protected void rtbButton_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) 
        { 
            this.GridExport(rgProcess, "ACFProcess", e.Item.Text, DCCPP.BusinessEntities.Enums.PdfOrientationEnum.Landscape); 
        } 
0
Daniel
Telerik team
answered on 18 Aug 2009, 08:10 AM
Hello Alex,

The following line causes the error:
radGrid.ExportSettings.ExportOnlyData = false;  

By default, when your export to CSV, all IScriptControls will be removed from the exported page. This includes your picker but doesn't affect the RequiredFieldValidator. The result is that your validator tries to find a non-existing control, thus causing an error.
To sidestep the error you should set ExportOnlyData property to true. This way all controls will be removed from the page.

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Alex
Top achievements
Rank 1
Share this question
or