Q:

Function for setting default values of controls in web browser control

I wanted to define a public function by which I can set default values of some controls in a web browser control.
The web browser shows an HTML file.
Here is what I have come up with so far;however,the "NullReferenceException was unhandled" occurs:
public void SetDefaultValue(string ControlID,string Value)
{
    webBrowser1.Document.GetElementById(ControlID).InnerText = Value;
}

A:

You need to wait for the document to get loaded properly
public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
{
   var webBrowser = sender as WebBrowser;
   webBrowser.DocumentCompleted -= WebBrowser_DocumentCompleted;

  webBrowser1.Document.GetElementById("Name").InnerText = "Hello World";

}    

private void btnClick(object sender, EventArgs e)
{
     var wbrowser = new WebBrowser(); // or can be existing object
      // Add web broswer to form or panel here.. 
     wbrowser.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
     wbrowser.Navigate("your_page_url_here");
}

