window.print() ??

C

cmrchs

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...
 
A

Ashish M Bhonkiya

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:printForm();");
}

this should help.

Regards
Ashish M Bhonkiya



Chris C said:
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...
 
A

avnrao

in button click handler, try this
RegisterStartupScript("Print", "<script
language='javascript'>window.print()</script>");

Av.
 
H

Hans Kesting

Chris C said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top