简体   繁体   中英

OnClientClick event for keeping track of prints?

I am trying to keep track of prints that are made for a page. The page has Print this page link. And the code for it is like below: This is written in .cs file as there are many conditions for displaying this. And i am appending here using String Builder.

sbOutput.AppendFormat("<td align=\"right\" valign=\"bottom\"><div style =\"float:right;text-align:right; valign:bottom;width:200px\"class=\"print_button notPrinted\"><a class=\"notPrinted\" href=\"#\" onclick=\"window.print();\">PRINT THIS COUPON </a><img src=\"images/print-icon-34x34.gif\" class=\"notPrinted\" align=\"absmiddle\" /></div> </td></tr></table>", couponid, Userid, locationid);

Do i have to use onclientclick or something else??

Thanks so much in advance.

since you seem to print on the client side only, you could do

<a href=\"counter.aspx\" onclick=\"window.print();\">PRINT THIS COUPON </a>

On the server side, implement the counter.aspx page to just count the request and quit silently. Make sure, the window.print() will return true - otherwise the link is not executed.

Good option would be to write a Javascript function to enable Ajax call, so that you can send a request to server to record the print coomand.

<a href="return RecordPrint();">PRINT THIS COUPON</a>

function RecordPrint() {

// Make a AJAX Call to your server Page to record Print Command.
// printRecorded : success from server

If(printRecorded)
{
  window.print();
}

return false;

}

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM