--- title: "How to: Access the HTML Source in the Managed HTML Document Object Model" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "managed HTML DOM" - "HTML [Windows Forms], accessing in Windows Forms" ms.assetid: 53db79fa-8a5e-448e-88c2-f54ace3860b6 --- # How to: Access the HTML Source in the Managed HTML Document Object Model The and properties on the control return the HTML of the current document as it existed when it was first displayed. However, if you modify the page using method and property calls such as and , these changes will not appear when you call and . To obtain the most up-to-date HTML source for the DOM, you must call the property on the HTML element. The following procedure shows how to retrieve the dynamic source and display it in a separate shortcut menu. ### Retrieving the dynamic source with the OuterHtml property 1. Create a new Windows Forms application. Start with a single , and call it `Form1`. 2. Host the control in your Windows Forms application, and name it `WebBrowser1`. For more information, see [How to: Add Web Browser Capabilities to a Windows Forms Application](how-to-add-web-browser-capabilities-to-a-windows-forms-application.md). 3. Create a second in your application called `CodeForm`. 4. Add a control to `CodeForm` and set its property to `Fill`. 5. Create a public property on `CodeForm` called `Code`. [!code-csharp[DisplayWebBrowserCode#1](~/samples/snippets/csharp/VS_Snippets_Winforms/DisplayWebBrowserCode/CS/CodeForm.cs#1)] [!code-vb[DisplayWebBrowserCode#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/DisplayWebBrowserCode/VB/CodeForm.vb#1)] 6. Add a control named `Button1` to your , and monitor for the event. For details on monitoring events, see [Events](/dotnet/standard/events/index). 7. Add the following code to the event handler. [!code-csharp[DisplayWebBrowserCode#2](~/samples/snippets/csharp/VS_Snippets_Winforms/DisplayWebBrowserCode/CS/Form1.cs#2)] [!code-vb[DisplayWebBrowserCode#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/DisplayWebBrowserCode/VB/Form1.vb#2)] ## Robust Programming Always test the value of before attempting to retrieve it. If the current page is not finished loading, or one or more of its child objects may not be initialized. ## See also - [Using the Managed HTML Document Object Model](using-the-managed-html-document-object-model.md) - [WebBrowser Control Overview](webbrowser-control-overview.md)