I have been trying to change the HTML code of a select tag in an HTML code but whenever I do that the
"Object reference not set to an instance of an object"
error occurs.This is the C# code:
public void SetDefaultValue(string ControlID,string Value)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElement list = doc.GetElementById(ControlID);
list.OuterHtml = Value;
}
private void Form1_Load(object sender, EventArgs e)
{
htmlLoadWebbrowser1.SetDefaultValue("D8876943-5861-4D62-9249-C5FEF88219FA", "");
}
The function is supposed to change the inner code of an HTML page,it receives the ID of the control by "controlID" and generates the inner code by "Value".
I suspect that I need to call it elsewhere,the problem is I do not know where
Thank you.
VulpesPosted Apr 27, 2013, 4:51 PM
The best thing to do would be to handle the webbrowser's DocumentCompleted event and call your method from there:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx
If you only want to call this method when a particular page is loaded, you can check the