Link to home
Create AccountLog in
Avatar of tryokane
tryokane

asked on

How to hide the url from being printed on a page?

I have a web application(ASP.Net).When i am trying to print the page its showing the url on the page along with details.Can anyone suggest how to avoid the url from being printed on the page.Can we do it programmatically?
Avatar of Pratima
Pratima
Flag of India image

string url = "http://localhost:1787/WebSite2/Default2.aspx";

        Response.Write(url.Substring(url.LastIndexOf("/")+1));
  string url = Request.CurrentExecutionFilePath;

        Response.Write(url.Substring(url.LastIndexOf("/") + 1));
Do you mean url at the bottom of page on the IE's Print Preview?

AFAIK, This is client configuration and you cannot control it programatically. Go to File -> Page Setup and change it at "Headers and Footers".
Avatar of tryokane
tryokane

ASKER

Can we change programmatically other than changing inthe page setup?
Can you show your code ...where you need it?
There is a page with print button within the page.
You may consider to use an ActiveX here to do the job http://www.codestore.net/store.nsf/unid/EPSD-55TPMN?OpenDocument, but it wouldn't work if user does not allow random ActiveX controls to be run on their browser.
I need to just install this one and else i have to make any changes??
Places ScriptX.cab (downloadable from my link above) at the same location of web page, then paste following code within BODY tag of the web page

<object classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" id="factory" codebase="ScriptX.cab#Version=5,60,0,375" style="display:none" viewastext>
</object>

User will be automatically prompted to install the component at the first time. Most of them will probably just say yes.
Next you need a script to activate the object.

function PrintWithNoHeadersFooters() {
    document.factory.printing.header = ''
    document.factory.printing.footer = '';
    document.factory.printing.Print(true);
}

Finally, you need a clickable item to call the script.

<input type=button value="Print without Headers and Footers" onclick="PrintWithNoHeadersFooters()">
This is usual a big process.Can we do it from the asp.net coding??
>Can we do it from the asp.net coding??
Yes, just change from <input ...> to an ASP.NET's component, such as <asp:textbox../> or <asp:label.../>.

>This is usual a big process.
I dont think so, but no easy way for this approach since it is breaking personal settings of user's configuration.
I installed it in my machine and copied the scriptx.cab in to the web application folder.But when i am trying to print the page its still displaying the url at the bottom?How to avoid?
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script> 
PrintWithNoHeadersFooters()
 {
    document.factory.printing.header = ''
    document.factory.printing.footer = '';
    document.factory.printing.Print(true);
}
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<object classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" id="factory" codebase="ScriptX.cab#Version=5,60,0,375" style="display:none" viewastext>
</object>
 
    <form id="form1" runat="server">
    <div>
        &nbsp;<input type=button value="Print without Headers and Footers" onclick="PrintWithNoHeadersFooters()" id="Button1">
        </div>
    </form>
</body>
</html>

Open in new window

It's script error. At line 5, change to be

function PrintWithNoHeadersFooters()
It is taking time to print the page.How can we reduce the time?
The time depends on size of page. Reduce size will reduce time.
Ok i got how to print a particular page but how to print a different page when we place the print button on this page.Will it work on that page also?
ASKER CERTIFIED SOLUTION
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for the suggestions.It helped me.