473,320 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

window.print() ??

Hi,

how can I execute a window.print() (in javascript)
on a ASP-button control but only when all validation-controls on the page pass the validation-test.

I tried using in the Page_Load() :
Button2.Attributes.Add("OnClick", "javascript:window.print();");

It works well ..... too well actually 'cause it always prints, even when some validation-controls don't pass the validation-test.
any ideas ?
thnx
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 18 '05 #1
3 4577
Hi Chris C,

I have also faced the same situation i solved this by calling
Page_ClientValidate() function before printing. Don't directly call
window.print() instead

private void Page_Load(object sender, System.EventArgs e)
{
StringBuilder myScript = new StringBuilder();

myScript.Append("<script language='Javascript'>");
myScript.Append(" function PrintForm(){");
myScript.Append(" if (Page_ClientValidate()){");
myScript.Append(" window.print();}");
myScript.Append("}");
myScript.Append("</script>");

this.RegisterStartupScript("MyScript", myScript.ToString());

Button2.Attributes.Add("onclick","javascript:Print Form();");
}

this should help.

Regards
Ashish M Bhonkiya

"Chris C" <cm****@yahoo.com> wrote in message
news:ur*************@TK2MSFTNGP11.phx.gbl...
Hi,

how can I execute a window.print() (in javascript)
on a ASP-button control but only when all validation-controls on the page pass the validation-test.
I tried using in the Page_Load() :
Button2.Attributes.Add("OnClick", "javascript:window.print();");

It works well ..... too well actually 'cause it always prints, even when some validation-controls don't pass the validation-test.

any ideas ?
thnx
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &

ASP.NET resources...
Nov 18 '05 #2
in button click handler, try this
RegisterStartupScript("Print", "<script
language='javascript'>window.print()</script>");

Av.
"Chris C" <cm****@yahoo.com> wrote in message
news:ur*************@TK2MSFTNGP11.phx.gbl...
Hi,

how can I execute a window.print() (in javascript)
on a ASP-button control but only when all validation-controls on the page
pass the validation-test.

I tried using in the Page_Load() :
Button2.Attributes.Add("OnClick", "javascript:window.print();");

It works well ..... too well actually 'cause it always prints, even when
some validation-controls don't pass the validation-test.
any ideas ?
thnx
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...

Nov 18 '05 #3

"Chris C" <cm****@yahoo.com> wrote in message news:ur*************@TK2MSFTNGP11.phx.gbl...
Hi, .... Button2.Attributes.Add("OnClick", "javascript:window.print();");


Just a note: in "onclick" you don't need the "javascript:" prefix,
it's always a (javascript) function and can't be mistaken for a URL.

Hans Kesting
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jawahar Rajan | last post by:
All, I have a printer friendly page that is opened when a user clicks a link on my page to get the printer friendly version, How ever when they close out the printer friendly version and return to...
1
by: John | last post by:
I am having a problem with window.print in a popup window. I am creating 2 popup windows both with a print button in them, 1 works the other doesn't. Code runs in a javascript function on a...
2
by: dan | last post by:
This works in mozilla but I can't figure out why this won't work in IE. Say I have this html <html> header goes here header goes here
3
by: Craig | last post by:
First of all, this one is driving me crazy, so thanks in advance for any help!! I've got a javascript function in a parent document that generates an HTML document on the fly when a button is...
2
by: Asad | last post by:
I have a main window that creates a new window called printWin (which contains the printable format of the page). From the main window I embed a javascript in the printWin window that calls the...
1
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and...
6
by: bwucke | last post by:
Short: One window writes to <input>, the other reads the same <input>. Is it a race condition or are the reads/writes atomic? Long: My app has an option to print results in a nicely formatted,...
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
2
by: colinzhu | last post by:
I want to have the print dialog shown automatically after the the page is loaded, but when I try to call window.print() BEFORE the iframe, the print dialog is not shown at all. Anyone can help? ...
1
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am dumping the HTML content of a page using document.write. As part of this HTML code, I have an input "Print" button which does nothing but calling the window.print Window.print...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.