window.print() ??

  • Thread starter Thread starter cmrchs
  • Start date Start date
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...
 
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...
 
in button click handler, try this
RegisterStartupScript("Print", "<script
language='javascript'>window.print()</script>");

Av.
 
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
 
Back
Top