Jump to content

onclick: run 1)vb codebehind, 2)window.print() - ?

Guest Soundersfan

Recommended Posts

Guest Soundersfan

Hello,First-time poster, please bear with me...I have a aspx page that when the user clicks a button, I need it to run a vb sub on the code-behind page (which after hitting a SQL server, populates controls on the page) and then prints the page without the print confirm dialogue box.I can get it to work just running the vb sub on the code-behind page and using window.print(), but it still gives them the print confirm dialogue box.Or, I can get it to print the page without giving them the print confirm dialogue box, but I have to leave out calling the vb sub on the code-behind page.It's getting the javascript, vbscript and vb on the code-behind page to all work in the proper sequence that I cannot accomplish.Why do I want it to print without the print dialogue box? My next step will be to add a second print button that loops through the entire process a predetermined amount of time (for example, it may print 5 pages, each with different data from the vb sub).Here is my source code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FormID1.aspx.vb" Inherits="BarcodeCoverSheets_FormID1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script type="text/javascript">        function printpage() {            document.getElementById('btnfakeprint').click();           } </script>        <script type="text/javascript">            function nowprint() {                window.print();            }</script><script type="text/javascript">    DA = (document.all) ? 1 : 0    function HandleError() {        alert("\nNothing was printed. \n\nIf you do want to print this page, then\nclick on the printer icon in the toolbar above.")        return true;    }</script>    <script type="text/vbscript">Sub window_onunload()On Error Resume NextSet WB = nothingOn Error Goto 0End SubSub Print()OLECMDID_PRINT = 6OLECMDEXECOPT_DONTPROMPTUSER = 2OLECMDEXECOPT_PROMPTUSER = 1On Error Resume NextIf DA Thencall WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 1)Elsecall WB.IOleCommandTarget.Exec(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","","")End IfIf Err.Number <> 0 ThenIf DA Then Alert("Nothing Printed :" & err.number & " : " & err.description)ElseHandleError()End ifEnd IfOn Error Goto 0End SubIf DA Thenwbvers="8856F961-340A-11D0-A96B-00C04FD705A2"Elsewbvers="EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B"End Ifdocument.write "<object ID=""WB"" WIDTH=0 HEIGHT=0 CLASSID=""CLSID:"document.write wbvers & """> </object>"</script>    </head><body>    <form id="form1" runat="server">    <div>        <asp:Panel ID="pnlEntry" runat="server">            <asp:Label ID="lblLanID" runat="server" Visible="False"></asp:Label>            <asp:Label ID="lblFormsID" runat="server" Text="1" Visible="False"></asp:Label>            <asp:Label ID="lblDeptID" runat="server" Visible="False"></asp:Label>            <asp:Label ID="lblCalendarID" runat="server" Visible="False"></asp:Label>            <asp:Label ID="lblMinBatchID" runat="server"></asp:Label>            <asp:Label ID="lblMaxBatchID" runat="server"></asp:Label>            <asp:Label ID="lblLastUsedBatch" runat="server"></asp:Label>            <asp:Label ID="lblBatchNumberID" runat="server"></asp:Label>            <input type="button" value="Print" onclick="printpage()" id="btnPrint" />        </asp:Panel>            <asp:Label ID="lblAllBatchesUsed" runat="server" ForeColor="Red"                 Text="All batches were used today!" Visible="False"></asp:Label>            <br />        <asp:Image ID="Image5" runat="server"             ImageUrl="~/images/BarCode/asterisk.gif" />        <asp:Image ID="Image6" runat="server" ImageUrl="~/images/BarCode/I.gif" />        <asp:Image ID="Image7" runat="server" ImageUrl="~/images/BarCode/N.gif" />        <asp:Image ID="Image8" runat="server" ImageUrl="~/images/BarCode/C.gif" />        <asp:Image ID="Image9" runat="server"             ImageUrl="~/images/BarCode/asterisk.gif" />        <br />        <asp:Panel ID="pnlMain" runat="server" HorizontalAlign="Center" Visible="True">            <h3>INC<br />            <br />            <b>US                  CANADA</b><br />            <br />            <b>BATCH CONTROL SHEET</b></h3>            <br />            <br />            <br />            <table cellpadding="8" cellspacing="0">                <tr align="left">                    <td colspan="2">                        BATCH DATE:                         <asp:Label ID="lblDate2" runat="server" Font-Size="Medium"                             Font-Underline="True" Font-Bold="True"></asp:Label>                    </td>                    <td colspan="1">                        BATCH NUMBER:                         <asp:Label ID="lblBatch2" runat="server" Font-Size="Medium"                             Font-Underline="True" Font-Bold="True"></asp:Label>                    </td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr align="left">                    <td colspan="2">                        NUMBER OF VOUCHERS:</td>                    <td>                        __________________________________</td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr align="left">                    <td>                        CONTROL TOTALS:</td>                    <td>                        VENDOR NUMBER</td>                    <td>                        __________________________________</td>                </tr>                <tr align="left">                    <td>                         </td>                    <td>                        INVOICE AMOUNT</td>                    <td>                        __________________________________</td>                </tr>                <tr align="left">                    <td>                         </td>                    <td>                        SELL AMOUNT</td>                    <td>                        __________________________________</td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr align="left">                    <td>                        INPUT BY:</td>                    <td>                        __________________</td>                    <td>                         </td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr align="left">                    <td>                        APPROVED BY:</td>                    <td>                        __________________</td>                    <td>                         </td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr>                <td> </td>                <td></td>                <td></td>                </tr>                <tr align="center">                    <td colspan="3">                        <asp:Image ID="Image10" runat="server"                             ImageUrl="~/images/BarCode/asterisk.gif" />                        <asp:Image ID="Image11" runat="server" ImageUrl="~/images/BarCode/Z.gif" />                        <asp:Image ID="Image12" runat="server" ImageUrl="~/images/BarCode/Z.gif" />                        <asp:Image ID="Image13" runat="server" ImageUrl="~/images/BarCode/1.gif" />                        <asp:Image ID="ImgDate1" runat="server" />                        <asp:Image ID="ImgDate2" runat="server" />                        <asp:Image ID="ImgDate3" runat="server" />                        <asp:Image ID="ImgDate4" runat="server" />                        <asp:Image ID="ImgDate5" runat="server" />                        <asp:Image ID="ImgDate6" runat="server" />                        <asp:Image ID="ImgBatch1" runat="server" />                        <asp:Image ID="ImgBatch2" runat="server" />                        <asp:Image ID="ImgBatch3" runat="server" />                        <asp:Image ID="Image14" runat="server"                             ImageUrl="~/images/BarCode/asterisk.gif" />                    </td></tr>                <tr align="center">                    <td colspan="3">                        <h3><b>ZZ1<asp:Label ID="lblDate" runat="server"></asp:Label>                        <asp:Label ID="lblBatch" runat="server"></asp:Label>                        </b>                            <asp:Button ID="btnfakeprint" runat="server" Width="0px" />                            <input type="button" onclick="nowprint()" id="nowprint" visible="True" size="0"/>                        </h3>                    </td></tr>            </table>        </asp:Panel>        <br />        <br />        <br />        <br />    </div>    </form></body></html>

And here is my code-behind:

Imports SystemImports System.DataImports System.Data.SqlClientPartial Class BarcodeCoverSheets_FormID1    Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If Not Page.IsPostBack Then            lblLanID.Text = Mid(User.Identity.Name, 8)            lblDeptID.Text = Request.QueryString("DeptID")        Else        End If    End Sub    Protected Sub btnfakeprint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnfakeprint.Click        GetLastUsedBatch()    End SubSub GetLastUsedBatch()Does a Select on the SQL server here, then populates some images on the web page.  Then,                If Not Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "ClientScript") Then                    Dim script As String = "<script type='text/javascript'> nowprint(); </script>"                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "ClientScript", script)                End If        cmd.Dispose()        strSQLConn.Close()        strSQLConn.Dispose()    End Sub

Thank you for taking the time to help me!!!John

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...