Click here to Skip to main content
13,400,930 members (35,783 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,

i've an application with print option using javascript...its working properly sometimes.. and not working sometimes..not working means data(chart images) is not displayed when print button is clicked..

May I know wher could be the problem...and how to solve it??

<%@ Page Title="" Language="C#" MasterPageFile="~/Reports/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Reports_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

 <link href="../Css/Styles.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">

        function Clickheretoprint() {
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=750, height=500, left=100, top=25";
            var content_vlue = document.getElementById("print_content").innerHTML;

            var docprint = window.open("", "", disp_setting);
            docprint.document.open();

            docprint.document.write('</head><body onLoad="self.print()"><center>');
            docprint.document.write(content_vlue);
            docprint.document.write('</center></body></html>');
            docprint.document.close();
            docprint.focus();
        }
    </script>
    <script type="text/javascript">
        function OnMoreInfoClick(url) {
            alert(url);

        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <table style="width: 850px">
                <tr>
                    <td align="center" valign="bottom" colspan="2" style="width: 100%">
                        <asp:Label ID="lblDistrict" runat="server" Text="Name of the District :"></asp:Label>
                        <asp:ComboBox ID="ddlDistrict" runat="server" AutoCompleteMode="Suggest" Width="170px"

                            TabIndex="1">
                        </asp:ComboBox>
                        <asp:Button ID="Button1" runat="server" Text="Show Report" OnClick="btnSearch_Click"

                            CssClass="btnStyle" TabIndex="2" />
                        <a href="javascript: void (Clickheretoprint())" title="Print" style="font-size: 18px">
                            Print</a>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2" style="width: 100%">
                        <asp:CheckBox ID="chkvalue" runat="server" Text="Show Values" AutoPostBack="true"

                            OnCheckedChanged="chkvalue_CheckedChanged" />
                        <asp:Label ID="lblError" runat="server" Text="Error"></asp:Label>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
                    </td>
                </tr>

                <tr>
                    <td colspan="2">
                        <div class="style3" id="print_content">
                            <table style="width: 100%">
                                <tr>
                                    <td colspan="2" align="left">
                                        <asp:Label ID="lblConnectivityRouters" runat="server" Style="background-color: #DCDCDC;"

                                            Text="202:Total Number of Districts With Routers,Modems,Dedicated Computers(Servers) and Others."></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="left">
                                        <asp:Chart ID="Chart6" runat="server" Width="800px" Height="225px" Style="margin-top: 7px" Palette="BrightPastel">
                                            <MapAreas>
                                                <asp:MapArea Coordinates="0,0,0,0" />
                                            </MapAreas>
                                            <ChartAreas>
                                                <asp:ChartArea Name="ChartArea1">
                                                </asp:ChartArea>
                                                <%--<asp:ChartArea Name="ChartArea1">
                            <Area3DStyle />
                        </asp:ChartArea>--%>
                                            </ChartAreas>
                                            <Legends>
                                                <asp:Legend Name="Legend1">
                                                </asp:Legend>
                                            </Legends>
                                        </asp:Chart>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>

            </table>


</asp:Content>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;

public partial class Reports_Default : System.Web.UI.Page
{


    RptConnectivityYesNobyDistrict conn = new RptConnectivityYesNobyDistrict();
    Information objInf = new Information();
    RptComputesByDistrictRespondent rpt = new RptComputesByDistrictRespondent();
    DataTable dt = new DataTable();
    DataSet ds1 = new DataSet();
    DataTable dt1 = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //if (Session["login"] == null)
            //{
            //    Response.Redirect("~/index.aspx");
            //}
            //lblError.Visible = false;
            BindDistrict();
            ConnectivityRoutersModemsByDistrict();
        }
    }
    public void BindDistrict()
    {
        DataSet ds = new DataSet();
        ds = objInf.GetDistrictDetails();
        ddlDistrict.DataSource = ds.Tables[0];
        ddlDistrict.DataMember = "intDistrictid";
        ddlDistrict.DataTextField = "strDistrictName";
      
        ddlDistrict.DataValueField = "intDistrictid";
        ddlDistrict.DataBind();

        ListItem lstItem = new ListItem("----All Districts----", "0");
        ddlDistrict.Items.Insert(0, lstItem);

    }
    public void ConnectivityRoutersModemsByDistrict()
    {
        string desktop2 = "";
        int intValue = Convert.ToInt32(ddlDistrict.SelectedValue.ToString());
        rpt.DistrictID = intValue;
        if (intValue == 0)
        {
            rpt.Mode = 2;
        }
        else
        {
            rpt.Mode = 1;
        }

        ds1 = rpt.GetConnectivityRoutersModemsDetails();

        dt1 = ds1.Tables[0];
        DataView data2 = new DataView();
        if (dt1.Rows.Count > 0)
        {
            lblConnectivityRouters.Visible = true;
            lblError.Visible = false;         
            for (int i = 1; i < ds1.Tables[0].Columns.Count; i++)
            {
                desktop2 = ds1.Tables[0].Columns[i].ToString();
                Chart6.Series.Add(desktop2);
                data2 = new DataView(dt1);
                Chart6.Series[desktop2].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;
                Chart6.ChartAreas[0].Area3DStyle.Enable3D = true;
                Chart6.ChartAreas[0].Area3DStyle.Inclination = 35;
                Chart6.ChartAreas[0].Area3DStyle.IsRightAngleAxes = false;
                Chart6.ChartAreas[0].Area3DStyle.PointDepth = 75;
                Chart6.ChartAreas[0].Area3DStyle.PointGapDepth = 50;
                Chart6.ChartAreas[0].Area3DStyle.Rotation = 1;
                Chart6.ChartAreas[0].Area3DStyle.WallWidth = 5;
                Chart6.ChartAreas[0].Area3DStyle.LightStyle = LightStyle.Realistic;
                Chart6.ChartAreas[0].ShadowColor = Color.FromArgb(100, Color.LightGray);

                Chart6.ChartAreas[0].Area3DStyle.IsClustered = true;
                Chart6.ChartAreas[0].AxisX.LineColor = Color.FromArgb(100, Color.Silver);
                Chart6.ChartAreas[0].AxisX.LineWidth = 0;
                Chart6.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
                Chart6.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
                Chart6.ChartAreas[0].AxisX.ScaleBreakStyle.BreakLineStyle = BreakLineStyle.None;
           

                Chart6.ChartAreas[0].AxisY.LineColor = Color.FromArgb(100, Color.LightGray);
                Chart6.ChartAreas[0].AxisY.LineWidth = 0;
                Chart6.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
                Chart6.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;

                Chart6.ChartAreas[0].AxisX2.LineColor = Color.FromArgb(100, Color.LightGray);
                Chart6.ChartAreas[0].AxisX2.LineWidth = 0;
                Chart6.ChartAreas[0].AxisX2.MajorGrid.Enabled = false;
                Chart6.ChartAreas[0].AxisX2.MajorTickMark.Enabled = false;

                Chart6.ChartAreas[0].AxisY2.LineWidth = 0;
                Chart6.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
                Chart6.ChartAreas[0].AxisY2.MajorTickMark.Enabled = false;
                chkvalue.Visible = true;
                if (chkvalue.Checked == true)
                {
                    Chart6.Series[desktop2].IsValueShownAsLabel = true;
                }
                else
                {
                    Chart6.Series[desktop2].IsValueShownAsLabel = false;
                }
                Chart6.Series[desktop2].ChartArea = "ChartArea1";
                Chart6.Series[desktop2].Points.DataBindXY(data2, "DisigantionName", data2, desktop2);

            }
        }
        else
        {
            chkvalue.Visible = false;
            lblError.Visible = true;
            lblError.Text = "Data Not Available!";
            lblError.ForeColor = Color.Red;
            lblConnectivityRouters.Visible = false;
          
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        ConnectivityRoutersModemsByDistrict();
    }
    protected void chkvalue_CheckedChanged(object sender, EventArgs e)
    {
        ConnectivityRoutersModemsByDistrict();
    }
}
Posted 31-Jul-12 22:32pm
Updated 1-Aug-12 0:43am
v2
Comments
Christian Graus 1-Aug-12 16:42pm
   
Do you mean your code is supposed to show them and it doesn't, or do you mean they are visible on the form but don't print ?
ryanb31 6-Aug-12 14:33pm
   
What does happen?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.180218.2 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100