0

I am currently using .NET MAUI Blazor Hybrid to create an app where users can print filled out receipts. The issue is that after I hit either print or cancel, I get the following error:

Received unexpected acknowledgement for render batch 3

I'm not quite sure what to try to fix it. I did try just the following in the js script:

var t_divContents = document.getElementById("PrintDivision").innerHTML;
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
document.body.innerHTML = headstr + t_divContents + footstr;
window.print();
window.close();

which works in that it doesn't cause an error, but it means my page is now just the specific content I wanted and nothing else.

Any help would be greatly appreciated.

  • are you sure element with ID PrintDivision exists? – Muhammad Saqlain Jan 18 '23 at 08:34
  • Yes, it grabs it correctly. Its just that when closing the print preview window, it causes a the error I mentioned. – Christopher Recinos Jan 18 '23 at 08:44
  • I guess this is because you are modifying too much of the DOM. Blazor keeps rerendering when necessary and has its own "DOM" relations/references. When you modify everything like this, you are breaking the references it knows and when rerendering, it does not find the elements to analyze and assess to rerender because you modified without Blazor being informed. – T.Trassoudaine Jan 18 '23 at 09:34
  • You are definitely correct. After testing a few things like reassigning the document.body contents back to original the page, the rendering stays correct, but all of the events/actions are broken. Is there anyway around this? – Christopher Recinos Jan 18 '23 at 17:39
  • 1
    Well, this is the purpose of Blazor to rerender, so you should be able to display what you want by using blazor logic instead of JS. – T.Trassoudaine Jan 18 '23 at 18:41
  • I don't see how that matters here. The issue is that after trying to print a page or element using js window.print, it throws an error. However, if you try to print with ctrl-p, it doesnt create any error, so there must be a way for this to work with window.print – Christopher Recinos Jan 20 '23 at 09:36
  • Why do you specifically need to display it through JS ? Why can't you display it using c#/Blazor logic ? – T.Trassoudaine Jan 20 '23 at 15:51
  • I'm not sure what you mean by display? I am trying to print a page. – Christopher Recinos Jan 20 '23 at 20:49
  • Try [this](https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div), this should allow you to print a specified HTML element without modifying the current page. – T.Trassoudaine Jan 23 '23 at 10:54

0 Answers0