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
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.
_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.
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();
Related
I have a C# WinForms application which I need to open a url through it.
The actual task is to display a web page without all it's functionality (changing url/go back button/etc...), do some actions in that site and then retrieve information from it according to what the user entered/did in that site.
Iv'e already tried the WebBrowser option, but it's opening the url site in a browser with all of it's functionality:
System.Windows.Forms.WebBrowser WebBrowser1 = new System.Windows.Forms.WebBrowser();
WebBrowser1.Navigate(new Uri("https://stackoverflow.com/questions/59766190/open-a-url-site-in-a-winforms-window-and-not-from-the-browser"), true);
WebBrowser1.BringToFront();
Any ideas?
Thanx :)
You're passing true as the second argument to the Navigate(Uri url, bool newWindow) method, which specifies that it should open the url in a new window (see the Microsoft documentation).
Changing your code so that it passes false for the newWindow argument will cause the url to be opened in the WebBrowser control instead (you also need to add the control to the form's Controls collection):
System.Windows.Forms.WebBrowser WebBrowser1 = new System.Windows.Forms.WebBrowser();
this.Controls.Add(WebBrowser1);
WebBrowser1.Navigate(new Uri("https://stackoverflow.com/questions/59766190/open-a-url-site-in-a-winforms-window-and-not-from-the-browser"), false);
I have this browsercontroller and wonder how can I scroll down to the bottom of the page? I don't know the right command for this one
Here is my part of my code
Browser browserController = new Browser(); //call browser controlle
Searcher searchKey = new Searcher();
browserController.browserCloser("iexplore"); //close all recent open IE to avoid issues
using (IE browser = new IE(browserController.URLData())) //original code but with time out exception
{
browser.AutoClose = false;
browser.WaitForComplete(40);
Thread.Sleep(20000);
}
I need to scroll down to the IE and wait for the item to load
this is the website I'm checking https://hpe.wd5.myworkdayjobs.com/Jobsathpe/
I need to load all the results in the page
Do not use Thread.Sleep() in UI thread. It usualy blocks any UI actions even these which was invoked just before this call. Use Timer instead.
Codebehind:
scrollTo method
create a control at the bottom of the page... and Focus
Client side:
scrollTo, scrollBy
I am making a web app in asp.net using c# that collects a lot of information from http web services at one time. Since this data collection process takes 10-20 seconds, I want to display a small loading frame with a small rotating image.
To make this happen on one page, I have a div called loadingdiv for which I set the Visible property of to false during PageLoad. When my "find movies" button is pressed, the c# code is supposed to hide the content that was originally on the page, show the loading image while loading the web service information in the backend, then hide the loading image and bring up the data display div.
If I comment out the class that loads the data from the webservices, this works fine. But as soon as I add my web service information it completely skips over the loadingdiv.Visible = true line and just does the 10-20 second operation.
Here's the relevant lines of code.
protected void btnFindMovies_Click(object sender, EventArgs e)
{
//Hides the main content that contained search options for movies
thisarticle.Visible = false;
articlediv.Visible = false;
lblGenres.Visible = false;
ratingdiv.Visible = false;
List<int> gList = new List<int>(); //Genre List
/* Other code that goes through checkboxes to find out which genres
to search for in the movie search */
string title = "Movie Title Here";
Page.Title = title;
loadingdiv.Visible = true; //Shows loading div before completing search
MovieSearch search = new MovieSearch(gList); //Intensive web service use
(10-20 seconds)
loadingdiv.Visible = false; //removes the loading div from the screen
}
How can I get the loadingdiv to show up while my web service operations are going through?
Everything in that method happens before any response is served to the user. This means that the following happens:
The user clicks your button.
A request is sent to the server and a postback occurs.
During the postback, btnFindMovies_Click is fired. You set Visible = true, wait for the web services to return their information and then set Visible = false.
The response is served to the browser.
Because this is all done on the same request, nothing is returned to the browser until all of this is done, which effectively eliminates the loadingdiv.Visible = true; line entirely.
If you want a loading div to show while some server-side code issues requests to web services, you will have to use AJAX to make these calls asynchronously and use Javascript to hide/show the loading div accordingly.
The following looks like a useful introductory guide to AJAX:
http://www.simple-talk.com/dotnet/asp.net/ajax-basics-with-jquery-in-asp.net/
I'm writing an app for Windows Phone 7/Silverlight. When the app is either tombstoned and reactivated while on the app page containing the WebBrowser control (I've saved the Uri in app state) or that same app page is navigated to by NavigationService.GoBack() or the phone back button, it seems that as long as the control still has the webbrowser.source value, it should then render just fine, but this is not the case. Unless I use the Navigate() method, it shows a white/blank screen, no matter what I try. Unfortunately, using the Navigate() method causes the web content to download again, unnecessarily. It's especially frustrating when only a GoBack() is used to get back to the application page with the WebBrowser control, which is quite frequent in my app.
private void OnWebBrowserLoaded(object sender, RoutedEventArgs e)
{
//webBrowser1.Source = CurrentUri; //does not work, results in white/blank browser page
webBrowser1.Navigate(CurrentUri); //works, but page has to reload from web, bad UX
}
Any suggestions on a way around this problem? I've also tried putting this same code in the page loaded handler. It behaves in the same poor manner.
I've also tried saving off the HTML (SaveToString) and reloading it from app state (NavigateToString), but the web page does not render completely for some reason, even though the HTML appears fine. Also, I'd like to have access to the Host and Uri properties. I could probably work around that, if I could get the HTML to render OK from NavigateToString.
Thanks,
Jay
You should use browsertask:
using Microsoft.Phone.Tasks;
WebBrowserTask browse = new WebBrowserTask();
browse.Uri = new Uri(URL, UriKind.RelativeOrAbsolute);
//new Uri(URL,UriKind.RelativeOrAbsolute);
browse.Show();
This should solve your issue.
URL will be the URL of the page you want to visit.
When I do something like this
webBrowser1 = new WebBrowser();
webBrowser1.Url = new Uri("http://google.com");
webBrowser1.Navigate("http://google.com");
all I get is a blank window.
when I step through this webBrowser1.Url stays = null after the second statement has executed. Why is that?
if I set the url property before I compile the web site loads correctly when I open the form.
So why can't I load a site dynamically?
If you've added the Web Browser control at design-time, you don't need to instantiate it in code (InitializeComponent will take care of that for you).
Remove this line:
webBrowser1 = new WebBrowser();
...and it should work fine for you.
If you are declaring the control in code, then you must add it to the visual tree of the parent form:
this.Controls.Add(webBrowser1);
where "this" refers to your form.
I had it in the constructor and it worked when I moved it out. I now call a function after the form loads to set the control
WebBrowser works asynchronously so you have to subscribe to WebBrowser.Navigated and wait until it will navigate to URL given and render resulting HTML