Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2007

Tip: Looking for answers? Try searching our database.

WebBrowser (loop automation)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cesar - 24 Sep 2007 19:54 GMT
Hello,

Background information ….

I have a VS2005 C# Windows forms app which has several text fields, one
button control and one webbrowser control that I use to display an external
webpage and based on the input data provided by the user, I perform some
tasks on the webpage. The idea is to go automatically go through several web
pages based in data captured by the user until I reach to a desired webpage.

All this works fine,
The user fills the data on the windows form, then clicks on the form's
button and the process starts.
The click method of this button does something like like …

private void btnSendData_Click(object sender, EventArgs e)
{

Uri myUri = new Uri (http://www.externalwebsite/page1.htm);
this.myWebBrowser.Url = myUri;
this.stageSecuence = 1;

}

I use a variable named "stageSecuence" in the next method to perform some
automated tasks depending on the webpage that is being processed.

Then for the webbrowser control I have the following method:

private void myWebBrowser_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{

switch (this.stageSecuence)
{
case 1:
    // perform some tasks like invoking the submit on the web page
    this.stageSecuence++;
case 2:
    // perform some other tasks
    this.stageSecuence++;

// and so on

}

Current situation,

Now, instead of executing this automation on the webpage based on the data
manually typed by the user; I want to call this process several times based
on  some database information.
I wrote the following code to perfom a loop (hoping to call sereval times
the automation process)

for (int i = 0; i < this.numberOfTableRecords; i++)
{
    // get record info

    Uri myUri = new Uri (http://www.externalwebsite/page1.htm);
    this.myWebBrowser.Url = myUri;
    this.stageSecuence = 1;
}

By doing this I only get the myWebBrowser_DocumentCompleted method executed
only once for the last record of the loop; in fact this method is executed
once the loop has finished.

How can I get the DocumentCompleted method executed once for every record in
the loop ?
Can I call this method manually such as:
this.myWebBrowser_DocumentCompleted( … ) ??

Thanks in advance,
Cesar
Robbe Morris - [MVP] C# - 27 Sep 2007 14:27 GMT
You have to set up an event driven "loop" if you will.
You won't be able to use a for loop.

Essentially, you'll have class level private variables that hold
the page you are on and an array of pages you need to process.

You write a method that processes the steps.  When the user
hits a button, you fire step 1.  Then, in the document complete
event, you determine the page just processed and call the method
to process the next page.  You let the document complete event
drive the process not your for loop.

You could get fancier than this of course but it should suffice.

I wrote something like this to auto submit letters to ever member
of congress through their own individual web sites and custom
authentication schemes.

Signature

Robbe Morris [Microsoft MVP - Visual C#]
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorials/aspnet/270e9432-d236-47e7-b1af-5cd3abe27a75
/net-propertygrid-control.aspx


> Hello,
>
[quoted text clipped - 76 lines]
> Thanks in advance,
> Cesar

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.