Wednesday, September 29, 2010

How to save details and print a page

Useful links:
  1. Opening a window after postback
  2. Java script print function
  3. Apply diffrnet styles whlie printing
  4. Print fit to page and backgrounds
<%@ Page Language="C#" %>
<head runat="server">
    <script runat="server">
        private string script = @"'{0}','',
                'scrollbars=no,menubar=no, height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
        protected override void OnLoad(EventArgs e)
            string m = this.Request.QueryString.Get("mode");
            if (!string.IsNullOrEmpty(m))
                this.ClientScript.RegisterStartupScript(this.GetType(), this.GetType().Name,
                this.btnSaveAndPrint.Visible = false;
            else this.btnSaveAndPrint.Visible = true;
        protected void SaveAndPrint(object sender, EventArgs e)
            string page = this.Request.Url.ToString();
            if (page.Contains("?")) page = page + "&mode=print";
            else page = page + "?mode=Print";
            /// Save your data...
                string.Format(this.script, page),
    <form id="form1" runat="server">
        Thank you for purchaing our products</h1>
    <hr />
    <asp:TextBox runat="server" ID="txtName" Text="Name" /><br />
    <asp:TextBox runat="server" ID="txtAddress" Text="Address" /><br />
    <asp:TextBox runat="server" ID="txtEmail" Text="" /><br />
    <asp:TextBox runat="server" ID="txtPhone" Text="0123456789" /><br />
    <hr />
        I started this site in 2005 to write down simple but important code snippets which
        I may forget easily. Most of the posts/articles published in this site are not rock
        complicated but they are simple answers to questions, which people may find hard
        to remember How To Do them. Today in 2010, almost all posts/articles are common
        answers to the questions raised in Forms. All of these posts/articles been
        tested against certain criteria which suits to subject of the post. But it is essential
        you to understand the domain of the post and apply them in appropriate context.
        Most of the posts have being through couple of reviews after feedback from
        community users. However I DO NOT provide any warranty for these code snippets,
        which may work in your application context. Use these examples at your own risk.
        However if you find obvious syntax error or typo, please feel free to let me know
        by commenting them, so that I can improve the post for other community users
        of this site. Please remember you are NOT ALLOWED to COPY entire articles/posts
        and publish them your context without my knowledge and permission.
    <asp:Button runat="server" ID="btnSaveAndPrint" Text="Save and Print" OnClick="SaveAndPrint" />

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...