Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual studio 2005/2008 application

Posted on 2014-04-03
28
Medium Priority
?
485 Views
Last Modified: 2014-04-21
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
Comment
Question by:pranjal_ds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 9
  • 2
  • +1
28 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39975466
Can you open the site within your application (using Webbrowser) or does it have to be opened in external browser?
0
 

Author Comment

by:pranjal_ds
ID: 39978162
Site is opened in Internet Explorer 6.0 version only.
0
 

Author Comment

by:pranjal_ds
ID: 39980920
Have you found any solution to my problem?
Please reply.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39982668
No. It would have been easier if the site could be opened within your application.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39982946
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
 

Author Comment

by:pranjal_ds
ID: 39984980
Please give the code to open the site in my application. Then we can go further from this.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39985635
Add a webbrowser control on your form. Call its Navigate method with the URL.
0
 
LVL 25

Expert Comment

by:apeter
ID: 39985868
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39986133
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
 

Author Comment

by:pranjal_ds
ID: 39986161
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
 

Author Comment

by:pranjal_ds
ID: 39986202
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39986357
>I have successfully opened a sample website in my Visual studio.net 2008 application

Which of the above methods did you use?
0
 

Author Comment

by:pranjal_ds
ID: 39986464
Add a webbrowser control on your form. Call its Navigate method with the URL.  ------- given by CodeCruiser
0
 

Author Comment

by:pranjal_ds
ID: 39986485
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39988278
You can access an element in the site using following syntax

Msgbox WebBrowser1.Document.GetElementById("TextboxID").Value
0
 

Author Comment

by:pranjal_ds
ID: 39988617
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
 

Author Comment

by:pranjal_ds
ID: 39988687
If I use the way you gave I am getting error as in attached screenshot.
SS2.JPG
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39988997
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
 

Author Comment

by:pranjal_ds
ID: 39990847
Please guide how to view and get the HTML input control id from the HTML source code.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39991205
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
 

Accepted Solution

by:
pranjal_ds earned 0 total points
ID: 39998924
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
 

Author Comment

by:pranjal_ds
ID: 39999231
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39999445
Why do you want it across two apps? Why not access it in App1?
0
 

Author Comment

by:pranjal_ds
ID: 40000725
Because App1 is already coded by some other coder and I do not have access to his code.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40004631
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
 

Author Closing Comment

by:pranjal_ds
ID: 40012207
Solution given by CodeCruiser was correct, only a little bit difference in syntax.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

609 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