Print with paging temporarily disabled. Control is null in Javascript

3 posts, 0 answers
  1. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2010 Link to this post

    I have found multiple threads on this issue but none of the solutions work for me.

    I am using the solution from here:
    http://www.telerik.com/ClientsFiles/207185_printradgrid-ignorepaging.zip

    to print a grid with paging temporarily disabled.  However, this line always returns a null:

    var radGrid = $find(radGridId);



    I've tried using

    var

     

     

    grd = $find("<%= radgrdMyPrograms.ClientID %>");

    to no avail. I always get a null and then the .get_element().outerHTML fails and, of course, the

     

     

    .get_masterTableView().fireCommand(

     

    'EnablePaging', '') also fails.


    here is my entire .aspx:

     

     

    <asp:Content ID="Content1" ContentPlaceHolderID="MasterContentPlaceHolder" Runat="Server">
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
        function PrintRadGrid() {
            var grd = $find("<%= radgrdMyPrograms.ClientID %>");
            var previewWnd = window.open('about:blank', '', '', false);
            var sh = '<%= ClientScript.GetWebResourceUrl(radgrdMyPrograms.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radgrdMyPrograms.Skin)) %>';
            var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
            var htmlcontent = styleStr + "<body>" + grd.get_element().outerHTML + "</body></html>";
            previewWnd.document.open();
            previewWnd.document.write(htmlcontent);
            previewWnd.document.close();
            previewWnd.print();
            previewWnd.close();
            grd.get_masterTableView().fireCommand('EnablePaging', '');
        }
    </script>
    </telerik:RadScriptBlock>
    <style type="text/css">  
    .RadMenu .rmGroup .rmText  {  
        font-size: x-small;
        width: 110px; }  
    </style>
      
    <table width="100%" cellpadding="0px" cellspacing="0px" style="padding-bottom:4px;">
        <tr>
            <td style="width:220px;"><asp:Label ID="Label1" runat="server" class="LabelDarkGrayMedium" Text="My Programs" /> </td>
            <td><asp:ImageButton ID="btnPrint" runat="server" ImageUrl="../img/Print.gif" ToolTip="Print table"/></td>
        </tr>
    </table>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="radgrdMyPrograms">
                <UpdatedControls><telerik:AjaxUpdatedControl ControlID="radgrdMyPrograms" /></UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <xc:LinqDataSourceWrapper ID="ldsProgramsAllByUserName" runat="server" TypeName="DMCproWebApp.BALHelper" SelectMethod="GetProgramsAllByUserName" EnableObjectTracking="false" />
    <telerik:RadGrid ID="radgrdMyPrograms" runat="server" Width="100%" DataSourceID="ldsProgramsAllByUserName" EnableLinqExpressions="true"
        EnableEmbeddedSkins="false" Skin="DMCpro" ShowStatusBar="true"
        AutoGenerateColumns="false" AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" PageSize="20" >
        <ClientSettings EnableRowHoverStyle="true" Selecting-AllowRowSelect="true" />
        <GroupingSettings CaseSensitive="false" />
        <MasterTableView TableLayout="Fixed" DataKeyNames="ProgramID,ProgramName,ClientId,Client" >
            <ItemStyle Font-Size="Small" Wrap="false" />
            <AlternatingItemStyle Font-Size="Small" Wrap="false" />
            <Columns>
                <telerik:GridHyperLinkColumn HeaderText="Program #" DataTextField="ProgramID" SortExpression="ProgramID" UniqueName="ProgramID" 
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="80px" HeaderStyle-HorizontalAlign="Left" 
                    AllowFiltering="false" />
                <telerik:GridBoundColumn HeaderText="Program" DataField="ProgramName" SortExpression="ProgramName" UniqueName="ProgramName"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="150px" HeaderStyle-HorizontalAlign="Left"
                    AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="150px" />
                <telerik:GridBoundColumn HeaderText="AE" DataField="AEName" SortExpression="AEName" UniqueName="AE"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="35px" HeaderStyle-HorizontalAlign="Left" 
                    AllowFiltering="false" />
                <telerik:GridBoundColumn HeaderText="Start Date" DataField="StartDate" SortExpression="StartDate" UniqueName="StartDate"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="95px" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:MM/dd/yyyy}" DataType="System.String" 
                    CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" FilterControlWidth="60px" />
                <telerik:GridBoundColumn HeaderText="End Date" DataField="EndDate" SortExpression="EndDate" UniqueName="EndDate"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="95px" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:MM/dd/yyyy}" DataType="System.String" 
                    CurrentFilterFunction="LessThanOrEqualTo" AutoPostBackOnFilter="true" FilterControlWidth="60px" />
                <telerik:GridBoundColumn HeaderText="Status" DataField="Status" SortExpression="Status" UniqueName="Status"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="92px" HeaderStyle-HorizontalAlign="Left" 
                    CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="90px" />
                <telerik:GridBoundColumn HeaderText="Revenue" DataField="Revenue" SortExpression="Revenue" 
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right" 
                    AllowFiltering="false" />
                <telerik:GridHyperLinkColumn HeaderText="Client" DataTextField="Client" SortExpression="Client" UniqueName="Client" 
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="170px" 
                    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="170px" />
                <telerik:GridBoundColumn HeaderText="Market" DataField="Market" SortExpression="Market"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="90px" HeaderStyle-HorizontalAlign="Left" 
                    AllowFiltering="false" />
                <telerik:GridBoundColumn HeaderText="Bus. Source" DataField="BusinessSource" SortExpression="BusinessSource" 
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="100px" HeaderStyle-HorizontalAlign="Left" 
                    AllowFiltering="false" />
                <telerik:GridBoundColumn HeaderText="Pax" DataField="Guests" SortExpression="Guests"
                    HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="45px" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" 
                    AllowFiltering="false" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    </asp:Content>


    and the relevant codebehind:

    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnPrint.Click
        radgrdMyPrograms.AllowPaging = False
        radgrdMyPrograms.Rebind()
        ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "PrintGrid", "PrintRadGrid();", True)
    End Sub

     

     

  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 25 Oct 2010 Link to this post

    Hello Jerry,

    Please try the following approach:
    var radGrid = $telerik.findControl(document, "YouRadGridID");

    Visit the link below for more information about our static client-side methods:
    Telerik static client library

    Regards,
    Daniel
    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
  3. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 02 Nov 2010 Link to this post

    I ended up changing things to export to PDF and setting the styles so it resembled the on-screen grid better.

    I'll keep in mind your suggestion for the future, though.  Thanks!
Back to Top