I'm extremely new to Blazor server and experimenting with web pages in general, and having trouble figuring out how to properly attach event handlers to a modal that should fire different actions based on the current page. I just want to be able to send the pages information as an email on submit, but it ends up sending all rendered pages emails as it considers each event triggered.
I'm using Radzen's Blazor DialogService and am trying to follow the pattern in their documentation - attaching the methods to it like this
protected override void OnInitialized()
{
DialogService.OnOpen += Open;
DialogService.OnClose -= Close;
DialogService.OnClose += Close;
}
private void Open(string Title, Type type, Dictionary<string, object> parameters, DialogOptions options)
{
}
private void Close(dynamic result)
{
if (result == true)
{
JS.InvokeAsync<string>("DisableDialogSubmit", "nhDialogSubmit");
SendEmail();
}
}
async void Submit()
{
await SubmitModal();
DialogService.OnClose -= Close;
}
void OnInvalidSubmit()
{
}
async Task SubmitModal() => await DialogService.OpenAsync("Confirm Submission", (ds =>
@<div style="top: 25%">
<p Style="margin-bottom: 1rem">Submit Form?</p>
<div class="row">
<div class="col-md-12">
<RadzenButton id="nhDialogSubmit" Text="Submit" Disabled="false" Click="() => ds.Close(true)" Style="margin-bottom: 10px; width: 150px" />
<RadzenButton Text="Cancel" Click="() => ds.Close(false)" ButtonStyle="ButtonStyle.Secondary" Style="margin-bottom: 10px; width: 150px" />
</div>
</div>
</div>),
new DialogOptions() { Width = "350px", Top = "35%", Left = "25%" });
This code is copy pasted on each page with different logic in SendEmail() I got it working a little bit with that sort of ham fisted local event attaching and detaching, but it has side effects and I'm sure I'm using it completely wrong in the first place. I was hoping injecting the service as scoped would allow me to do this; would creating it as transient accomplish my implementation? I'm having a hard time finding the right things to search to manage events on a any service in a single page application, so any tips or pointers would be greatly appreciated!