1

Converting an older application into a Blazor Web Application. The older has a very basic PRINT Link as follows:

  <a class="print" href="javascript:window.print()">Print</a>

Is there a way to do this same (simple and easy web page print) by using a Radzen Button? I can't seem to figure out how to do the href within the Radzen Button

Here is an example of a Radzen Button that is also on the page. This calls a function called DetailsShowStatus (C#). Is there a simple C# print option I can use? Or - can I somehow call the jscript 'window:print' from within the Radzen button?

<RadzenButton Button Text="Edit Status" Click=@(args => DetailsShowStatus(carPK))  ButtonStyle="ButtonStyle.Primary" ></RadzenButton>
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ExecChef
  • 387
  • 2
  • 13
  • 2
    You need to inject a `IJSRuntime` property on your page and then call a javascript method from it (define a JS method that calls `window.print()` and call it with `JSRuntime.InvokeVoidAsync("PrintMethod")`... can't write a full answer now but this should be enough for you to google it – Jcl Apr 17 '23 at 15:48
  • Thank you @Jcl for this start. It really helped put me on the right path! – ExecChef Apr 17 '23 at 17:00

1 Answers1

4

Here's a demo page (based on what @Jcl suggested):

@page "/"
@inject IJSRuntime _js
<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<div class="m-2 p-2">
<button class="btn btn-primary" @onclick=this.PrintMe> Print Me</button>
</div>


@code {
    private async Task PrintMe()
        => await _js.InvokeVoidAsync("window.print");
}
MrC aka Shaun Curtis
  • 19,075
  • 3
  • 13
  • 31