Solved

How do i add remove Web browser control from a module

Posted on 2011-03-25
1
475 Views
Last Modified: 2012-05-11
I order to get page data from web site i'm using this code: (get page)
this code after a few pages donut work i think maybe because i'm  not add/remove web bowser properly from my form: "frmMain".
can some one fix it?

sample URL:
http://www.b144.co.il/search.aspx?txtNamePrivate=%D7%9C%D7%99%D7%91%D7%A9%D7%99%D7%A5&txtCityPrivate=%D7%A6%D7%A4%D7%AA&txtStreetPrivate=&txtStreetNPrivate=&_private=0&_p=&_lang=HE

 
Public Function Get_Page(ByVal sURL As String) As String

        Dim sResult As String = vbNullString
        Try
            Const cTitle As String = "144 ¿¿¿"
            Dim oWeb As New WebBrowser
            With oWeb
                oWeb.Name = "WebBrowser1"
                frmMain.Controls.Add(oWeb)
                .Visible = True
                .Navigate(sURL)
                Whit4(3)
                DoEvents()
                frmMain.Refresh()
                Debug.Print(oWeb.DocumentTitle)
                sResult = .DocumentTitle
                Dim iCount As Integer = 0
                Do Until InStr(sResult, cTitle) > 0
                    Whit4(3)
                    iCount = iCount + 1
                    sResult = .DocumentTitle
                    If iCount >= 3 Then
                        If len(sResult)=0 Then
                           oWeb.Dispose()
                           frmMain.Controls.Remove(oWeb)
                            Exit Try
                        end if
                    End If
                Loop
lbl_read_data:
                Dim sr As System.IO.StreamReader = New           System.IO.StreamReader(.DocumentStream, System.Text.Encoding.UTF8)
                sResult = sr.ReadToEnd()
                sr.Close()
                oWeb.Dispose()
                frmMain.Controls.Remove(oWeb)
            End With
            GC.Collect()
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString)
            'MsgBox(Err.Description & Chr(32) & Err.Number & vbCrLf & "Proc getrequestuelsource mod app actions")
        End Try
        Return sResult
        'sr = new System.IO.StreamReader(objRes.GetResponseStream(), System.Text.Encoding.GetEncoding("windows-1255"));

    End Function

Open in new window

0
Comment
Question by:rshaham
1 Comment
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 35220392
Perhaps it would work better if you added the webbrowser control to the form design time rather than runtime?

Another thought: you are trying to dispose the control prior to removing it from the control collection.  It may work better to remove it, then dispose...

frmMain.Controls.Remove(oWeb)
oWeb.Dispose()
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question