scrolling down in browser C# - c#

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

Related

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
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();

Blocking iframes in webbrowser control?

I have a problem with blocking iframes in the webbrowser control. Currently I am using this code:
foreach (HtmlElement x in ((WebBrowser)sender).Document.GetElementsByTagName("iframe"))
{
MessageBox.Show("iframe!"); //DEBUG
x.OuterHtml = #"<iframe src=""about:blank"" frameborder=""0"" style=""display:none;""></iframe>";
// x.OuterHtml = String.Empty; //gives the same result
}
It works but when navigating to www.popuptest.com , the application just freezes completely because of this code. It shows 2 "iframe!" message boxes and freezes after closing the second one.
I have found the 2 iframes in the source code of webpage (in the advertisements shown on that website). This is the code that is causing it to freeze:
(a=document.createElement("IFRAME"),a.frameBorder=0,a.style.height=0,a.style.width=0,a.style.position="absolute",t=a,document.body&&(document.body.appendChild(a),a=t))&&(a=a.contentWindow)&&(r="1",a.document.open(),a.document.write("<!doctype html><html><head></head><body></body></html>"),a.document.close(),k(a.document))
I guess it is because of the frame being created in a different way? I have tested it both on win7/IE10 and winXP/IE6 and the result is the same. On winXP, however, it crashes and opens the debugger instead of freezing and that is how I got the faulty code.
Is there a better/safer method of removing the content of iframes?
I would try disabling frames using Download Control (DLCTL_NO_FRAMEDOWNLOAD). Here's how it can possibly be done, although I haven't tried that myself. Let us know if that works for blocking frames or not.

div.Visible not executing before other code

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/

When using an ASP.Net UpdatePanel, requests from Popup window are blocked

All,
I have an UpdatePanel that is making a couple of long-running request to gather a lot of data. Sometimes it takes up to 90 sec to return.
The first request returns data that is rendered as a link to a document. Clicking the link opens a new browser window and the URL has a query string that tells the system which doc to open.
Here is a snip of code when rendering the link for the client:
HtmlAnchor alink = new HtmlAnchor();
alink.HRef = "javascript:openDocument('"+ item.Url +"')"; //item.Url;
// here is the JS on the client page
function openDocument(path) {
window.open(path);
}
So, when the user clicks the link, the popup window does open. The problem is that it waits until the UpdatePanel is complete with its request before the popup window sends its request.
I can copy the url from the popup, open a new browser and then paste the URL into the new browser and it opens the doc as expected.
This leads me to believe that the UpdatePanel is somehow blocking the popup window's request. I'd rather not make the user wait until the UpdatePanel's AJAX request has completed before the user can open docs from the first result.
How can I work around this blockage? I've tried creating buttons outside of the ContentArea of the UpdatePanel and simulating clicks, but nothing like that works either.
Does anyone have an idea about this?
Thanks in Advance!
The reason is that the pages are using Session state so any request blocks all other that share the same session key.
If your page does not write to the session then you can apply IReadOnlySessionState attribute to them so that they only block if there is a non-readonly request and not if all concurrent requests are using read-only Session.
public class YourPage: Page, IReadOnlySessionState { ... }

Show a loading animation while function completes

I have a function inside my .aspx.cs code which takes wuite a long time to do the processing until when I want to display a cool loading animation. I looked some of the earlier posts but either these didn't work for me, or were having solution specific to Page loading scenario (not loading a while a function completes).
I guess the right approach would be to fire a Javascript startLoader() function just before the the main function starts (which takes a long time), and then call a stopLoader() from the .aspx.cs itself to stop the loader when the function ends. Any suggestions how to implement this?
Yes, I've done this in ASP.NET Web From (not a ASP.NET MVC solution). You need to provide OnSubmit client side event handler. It basically break down to three parts: Javascript, HTML Div, and one line code behind:
Javscript:
function ShowLoading(e) {
// var divBg = document.createElement('div');
var divBg = document.getElementById('blockScreen');
var divLoad = document.createElement('div');
var img = document.createElement('img');
img.src = 'images/ajax-loader.gif';
divLoad.setAttribute("class", "blockScreenLoader");
divLoad.appendChild(img);
divBg.appendChild(divLoad);
document.getElementById('blockScreen').style.display = 'block';
// These 2 lines cancel form submission, so only use if needed.
//window.event.cancelBubble= true;
//e.stopPropagation();
}
function HideLoading() {
//alert('hideloading');
document.getElementById("form1").onsubmit = null;
document.getElementById('blockScreen').style.display = 'none';
//alert('done');
}
Add following DIV
<div id="blockScreen" class="blockScreen" style="display:none"> </div>
Finally, add the following to Page_Load in code behind.
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "submit", "ShowLoading()");
Now, all of your page postbacks are essentially have to call onsubmit event. It will display the animation before the page postback finishes.
if you really want to do, then the only way is webworkers. You've probably heard about them, or if not, i seriously recommend to have a look.
Yes, fire startLoader() on OnCliencClick of your button or whatever element you are using to fire the server-side event and call stopLoader() from the server-side at the end of your process. Something like this:
//rest of the server-side code above ...
Page.ClientScript.RegisterStartupScript(this.GetType(), "someKey", "stopLoader();", true);
If you don't mind that the browser is not responsive in the meantime, the simplest way of doing this is using an animated gif:
Activity indicators
ajaxload.info
webscriptlab
The trick is showing the image when starting your processing, and hiding it when finished. You can show it in an img, and use jQuery or whatever you want to show/hide it.
If you need the browser to keep responsive, use Web Workers. But be aware that some of the older browsers don't support it. See this reference

Categories