Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

Visual studio 2005/2008 application

Hi,

I need to access data from a text box or combo box from an open ASP.net application into a VB.Net application.

Please guide and provide resolution.
0
pranjal_ds
Asked:
pranjal_ds
  • 14
  • 9
  • 2
  • +1
1 Solution
 
CodeCruiserCommented:
Can you open the site within your application (using Webbrowser) or does it have to be opened in external browser?
0
 
pranjal_dsAuthor Commented:
Site is opened in Internet Explorer 6.0 version only.
0
 
pranjal_dsAuthor Commented:
Have you found any solution to my problem?
Please reply.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
CodeCruiserCommented:
No. It would have been easier if the site could be opened within your application.
0
 
Bob LearnedCommented:
If you are using Internet Explorer, there is the option of using IE Automation to enumerate all the open windows, and inspect that window to find what you are looking for.

InternetExplorer object
http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx
0
 
pranjal_dsAuthor Commented:
Please give the code to open the site in my application. Then we can go further from this.
0
 
CodeCruiserCommented:
Add a webbrowser control on your form. Call its Navigate method with the URL.
0
 
apeterCommented:
Use HMTLAgilityPack(http://htmlagilitypack.codeplex.com/) to open the site page in your vb.net application.  Parse the html which comes back to get the textbox/combo box value.
0
 
Bob LearnedCommented:
Internet Explorer automation example:

' Add a COM reference to 'Microsoft Internet Controls' to the project. 
' Add a .NET reference to Microsoft.mshtml to the project. 

' NOTE: 
' Don't add an Imports mshtml if you want your Intellisense to work. 

Imports System.Collections.Generic
Imports SHDocVw

Public Class InternetExplorerWindows

	Public Shared Function GetWindows() As Dictionary(Of String, String)
		Dim list As New Dictionary(Of String, String)()
		For Each window As InternetExplorer In New ShellWindows()

			' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2. 
			If TypeOf window.Document Is mshtml.HTMLDocument Then
				list.Add(window.LocationURL, DirectCast(window.Document, mshtml.HTMLDocument).body.innerHTML)
			End If
		Next
		Return list
	End Function

	Public Shared Function GetIFrameHTML(frameID As String) As Dictionary(Of String, String)
		Dim list As New Dictionary(Of String, String)()
		For Each window As InternetExplorer In New ShellWindows()

			' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2. 
			If TypeOf window.Document Is mshtml.HTMLDocument Then
				Dim doc As mshtml.HTMLDocument = DirectCast(window.Document, mshtml.HTMLDocument)
				If doc.getElementById(frameID) IsNot Nothing Then
					Dim frame As mshtml.HTMLIFrame = DirectCast(doc.getElementById(frameID), mshtml.HTMLIFrame)
					Dim window2 As mshtml.HTMLWindow2 = DirectCast(frame.contentWindow, mshtml.HTMLWindow2)
					Dim windowDocument As mshtml.IHTMLDocument2 = DirectCast(window2.document, mshtml.IHTMLDocument2)
					list.Add(window.LocationName, windowDocument.body.outerHTML)
				End If
			End If
		Next
		Return list
	End Function

End Class

Open in new window

0
 
pranjal_dsAuthor Commented:
I have successfully opened a sample website in my Visual studio.net 2008 application which contains a textbox and dropdownlist.
Now how to access the contents from textbox or dropdownlist in my Visual studio.net 2008 application?

Please suggest.
0
 
pranjal_dsAuthor Commented:
What is SHDocVw?
And do I have to add the above code to a Module?
Then where do I have to call the functions defined?
0
 
CodeCruiserCommented:
>I have successfully opened a sample website in my Visual studio.net 2008 application

Which of the above methods did you use?
0
 
pranjal_dsAuthor Commented:
Add a webbrowser control on your form. Call its Navigate method with the URL.  ------- given by CodeCruiser
0
 
pranjal_dsAuthor Commented:
I have added a webbroser control to the form and then set the URL property to the website URL and it opened the website when I executed the project.
0
 
CodeCruiserCommented:
You can access an element in the site using following syntax

Msgbox WebBrowser1.Document.GetElementById("TextboxID").Value
0
 
pranjal_dsAuthor Commented:
Hi,

I have created 1 application in VB.Net as TestApp and 1 sample website and added 1 textbox and dropdownlist to the website, I have opened the website in Form1 and accessing data from Form2 using MsgBox(Form1.WebBrowser1.Document.GetElementById(TextBox1.Text))   as suggested by you but I am getting blank value.

Attached is the screenshot.

Please suggest.
SS1.JPG
0
 
pranjal_dsAuthor Commented:
If I use the way you gave I am getting error as in attached screenshot.
SS2.JPG
0
 
CodeCruiserCommented:
You need to open your website and check its HTML source code to get the actual id of the HTML input control that your textbox gets rendered to and then use that ID in the line I provided.
0
 
pranjal_dsAuthor Commented:
Please guide how to view and get the HTML input control id from the HTML source code.
0
 
CodeCruiserCommented:
Right click in the browser and then click "View Source". Then read through the HTML to find the control. It will have a long name which will end in the name that you supplied to ASP.NET control.
0
 
pranjal_dsAuthor Commented:
I was able to get the value using below syntax:

MsgBox(Form1.WebBrowser1.Document.All("TBox1").GetAttribute("Value"))

Now I will try on the actual website and update you.
0
 
pranjal_dsAuthor Commented:
Hi,

Now I have a website opened in external application say App1 and I have created another application App2 and want to access the contents in Dropdown list currently active item from the website opened in App1.

Please suggest how this can be done.

Regards,
0
 
CodeCruiserCommented:
Why do you want it across two apps? Why not access it in App1?
0
 
pranjal_dsAuthor Commented:
Because App1 is already coded by some other coder and I do not have access to his code.
0
 
CodeCruiserCommented:
The comment that you have selected as the solution is not the solution so either select the correct solution or delete the question if it has not been answered.
0
 
pranjal_dsAuthor Commented:
Solution given by CodeCruiser was correct, only a little bit difference in syntax.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 14
  • 9
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now