Averla Team
Averla Team

Reputation: 427

How to reload web page inside the web browser control?

I have developed chrome embedded user control for calling web page in windows app. Now I need to refresh/reload the web page when user click button second time.

I have tried the code below, but it doesn't reload the page.

panel.Visible = true;
var settings = new CefSettings
{
    IgnoreCertificateErrors = true,
    CachePath = "<linktoabsolutecachepath>",
    LogFile = "<mylogfile>"
};
settings.CefCommandLineArgs.Add("enable-media-stream", "1");
_chromeBrowser.Refresh();
_chromeBrowser = new ChromiumWebBrowser(_puzzleUrl);

panel.Size = new Size(2000, 1650);
panel.Location = new Point(-450, 364);
panel.Controls.Add(_chromeBrowser);

I'm using ChromiumWebBrowser for loading the web page in the panel

Upvotes: 2

Views: 5898

Answers (3)

andy
andy

Reputation: 6079

_chromeBrowser.Stop(); //Stops loading the current page.
_chromiumWebBrowser.Reload();//Reloads the page being displayed. 
//This method will use data from the browser's cache, if available.

Upvotes: 1

Sergey Avdeev
Sergey Avdeev

Reputation: 930

I think it is not necessary to clear all controls and create a new browser every time a reload needed. Instead, you can use the old instance of ChromiumWebBrowser and do _chromeBrowser.Reload() (docs). All the rest of the code you posted is also unnecessary for refreshing.

Upvotes: 1

Averla Team
Averla Team

Reputation: 427

Finally I have found better way to solve this issue. Each time on initialising the ChromiumWebBrowser object its better to clear the panel which we assigning the chromiumBrowser control in the windows form.

You can clear the panel control :-

panel.Controls.Clear();

Upvotes: -1

Related Questions