Ajax page load using Web Browser Control

Posted by Neetha under C# on 6/22/2011 | Points: 10 | Views : 8971 | Status : [Member] | Replies : 1
I am new to .Net & C#, need help in loading Ajax page through Web Browser Control.
Here is the code which currently I am using, after navigating to login I am in process of search page which has ajax call.

private void searchNCPPageClick(string msg)
{
log.Debug("Processing Navigation to the NCP Search Project page...");
try
{
HtmlElementCollection elems = this.webBrNcp.Document.GetElementsByTagName("html")[0].All;
foreach (HtmlElement elem in elems)
{
if (!(elem.DomElement.GetType().ToString().Equals("mshtml.HTMLAnchorElementClass")))
{
continue;
}

if (elem.InnerHtml != null && elem.InnerHtml.Equals(IConstants.STR_SEARCH_PROJECT))
{
elem.InvokeMember("click");

waitTillLoad(this.webBrNcp);
this.m_pageStatus = true;
this.m_page = this.webBrNcp.Document.GetElementsByTagName("html")[0].OuterHtml;
break;
}
}
log.Debug("The Search Project Page navigated successfully.");
}catch(Exception ex)
{
log.Error("Error occurred while navigating Search Project page =" + ex.Message);
string errMsg = String.Format("Error occurred while navigating Search Project page in {0} - {1}", "searchNCPPageClick", ex.Message);
throw new ScreenScrapeException(errMsg, ex);
}
}


The method waitTillLoad is taken from - http://codingform.blogspot.com/2009/08/c-webbrowser-control-synchronization.html

private void waitTillLoad(WebBrowser webBrControl) {

WebBrowserReadyState loadStatus;
//wait till beginning of loading next page
int waittime = 100000;
int counter = 0;
while (true)
{
loadStatus = webBrControl.ReadyState;

Application.DoEvents();

if ((counter > waittime) || (loadStatus == WebBrowserReadyState.Uninitialized) || (loadStatus == WebBrowserReadyState.Loading) || (loadStatus == WebBrowserReadyState.Interactive))
{
break;
}
counter++;
}

//wait till the page get loaded.
counter = 0;
while (true)
{
loadStatus = webBrControl.ReadyState;
Application.DoEvents();

if (loadStatus == WebBrowserReadyState.Complete && webBrControl.IsBusy != true)
{
break;
}
counter++;
}
}


This works fine, but I would like to know the exact load time of the ajax request.

Thanks in Advance,
Neetha




Responses

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

windows based using webbrowser control

web based using iframe.

Mark as Answer if its helpful to you

Neetha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response