Native alert and confirm

Native friendly

Sometimes you don’t need a fancy box and the browser’s native alert or confirm boxes will do just fine.

With Wisej you can integrate the native alert and confirm with your server side .NET code with a single line. Call it on the server, it shows on the browser, blocks, and server execution resumes after the user decides what to do. Just like magic. With the added benefit that the native alerts block the browser.

Here is the code:

public static async Task Alert(string message)
{
    await Application.CallAsync("alert", message);
}
public static async Task Confirm(string message) { return await Application.CallAsync("confirm", message); }

public static async Task<string> Prompt(string message)
{
return await Application.CallAsync("prompt", message);
}

Now you can call Alert(“Thank you for playing.”) or Confirm(“Do you want to continue?”) in your server side code like this:

private async void button1_Click(object sender, EventArgs e)
{
    await Alert("Thank you for playing.");
    AlertBox.Show("Alert closed.");

    var result = await Confirm("Do you want to continue?");
    AlertBox.Show($"Confirm closed: {result}");
}

What you get is this:

Please be aware that while the native alert box is on the screen, the browser fully suspends all JavaScript execution – if the user doesn’t take any action and the session timeout kicks in, the session will expire.

Happy coding with Wisej!