Microsoft KB Archive/311292

= HOW TO: Find the src Attribute of a Frame Element in Visual Basic .NET =

Article ID: 311292

Article Last Modified on 4/21/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition

-



This article was previously published under Q311292





For a Microsoft Visual Basic 6.0 version of this article, see 297950.

IN THIS TASK
SUMMARY
 * Requirements
 * Hosting the WebBrowser Control in Visual Basic .NET
 * Complete Visual Basic .NET Code for Finding the src for Each Frame
 * Troubleshooting

REFERENCES



SUMMARY
This article demonstrates a way to programmatically find the src attribute of a frame element from Visual Basic .NET when hosting the WebBrowser control.

back to the top

Requirements
The following list outlines the hardware, software, network infrastructure, and service packs that are required:
 * Visual Basic .NET

This article assumes that you are familiar with the following topics:
 * Visual Basic .NET
 * Hosting WebBrowser control (Shdocvw.dll)

back to the top

Hosting the WebBrowser Control in Visual Basic .NET

 * 1) Open Visual Studio .NET, and create a new Visual Basic .NET Windows application.
 * 2) On the Project menu, click Add reference, and then click the COM tab in the upper left of the window.
 * 3) Browse the list of COM components. Double-click to select Microsoft Internet Controls and Microsoft HTML Object Library, and then click OK.
 * 4) In the toolbox, right-click the Windows form tab, and then click Customize toolbox. A small dialog box appears. By default, the COM tab is selected. Again, browse the components list until you find a component named Microsoft Web Browser, which points to Shdocvw.dll in your system32 directory. Select the Microsoft Web Browser check box, and then click OK.
 * 5) A new control named Explorer appears on the Windows form tab of your toolbox. This is the WebBrowser control that you can place on the form.

When you complete these steps, browse in your Web browser to a frameset page. Use the following code to obtain the src attribute of each of the frames in the frameset.

NOTES: For this project to work, you must set a reference to Microsoft HTML Object Library and Microsoft Internet Controls. If the code does not run, verify that these two components are selected by reviewing steps 1 through 3.

back to the top

Complete Visual Basic .NET Code for Finding the src for Each Frame
  Place a button on the Form1.vb. In the Click event of the button, paste the following code: Dim fDoc As MSHTML.IHTMLDocument Dim x As Integer

fDoc = AxWebBrowser1.Document For x = 0 To fDoc.All.length - 1 If fDoc.all.item(x).tagName = &quot;FRAME&quot; Then MsgBox(fDoc.all.item(x).src) End If Next fDoc = Nothing  Run the application. After a frameset page is loaded, click Button in the form to see the different src attributes of the different frame elements.

NOTE: The src values that you see are based on the parent frameset page. If any of the src values is changed dynamically by client-side or server-side script, you will not see these changes by using this method.

back to the top

Troubleshooting
As stated in the &quot;Hosting the WebBrowser Control in Visual Basic .NET&quot; section, make sure that you added the Microsoft HTML Object Library and Microsoft Internet Controls references to the project.

back to the top