dotnet browser throwing Reload site prompt

93 Views Asked by At

I am using dotnetbrowser 2.8 version

I have wpf page where I have 2 grids. one containing dotnetbrowser added to a grid and other contain a button. I am loading a webpage using dotnetbrowser and button present below to close the window/page.

I need to pass an integer value in url request every time to load webpage and I am using below code

public bool Index(int id)
        {
            LoadUrlParameters editId = new LoadUrlParameters(_actionIndex.Url + @"/" + id);
            bool b = LoadActionUrl(editId);
            return b;
        }

private bool LoadActionUrl(LoadUrlParameters urlParameters)
        {
            try
            {
                if (_browser != null)
                {
                    _browser.Navigation.LoadUrl(urlParameters);
                    return true;
                }
            }
            catch (Exception e)
            {
                
            }
            return false;
        }

The page loads first time without any issue but when invoked next time it throws below prompt . "Changes you made may not be saved" with Reload and Cancel buttons

I tried using the handlers to suppress to popups and other ways but no luck. Can you please provide me some help here.

enter image description here

1

There are 1 best solutions below

0
Roman Vasylenko On

You may consider using BeforeUnloadHandler to control the BeforeUnload dialog. In this handler, you can programmatically select whether to "stay" or "leave" the page. See an example below:

browser.JsDialogs.BeforeUnloadHandler =
new Handler<BeforeUnloadParameters, BeforeUnloadResponse>(p =>
{
    // Dialog title.
    string title = p.Title;
    // Dialog message.
    string message = p.Message;
    // The localized text of the "Stay" action.
    string stayActionText = p.StayActionText;
    // The localized text of the "Leave" action.
    string leaveActionText = p.LeaveActionText;
    // Create and display the dialog if necessary.
    // ...
    // The "Stay" action has been selected.
    return BeforeUnloadResponse.Stay();
});

More information is available in the documentation.