本文介绍了为什么OuterHTML功能会导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在HTML代码中更改选择标记的HTML代码,但每当我这样做时,



对象引用未设置到一个对象的实例



错误发生。这是C#代码:

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", "<SELECT id=\"D8876943-5861-4D62-9249-C5FEF88219FA\" multiple size=\"4\" name=\"drop1\"> <OPTION value=\"3\">item 3</OPTION></SELECT>");
}



该函数应该改变HTML页面中select标签的代码,它通过controlID接收控件的ID并生成内部代码由价值。我怀疑我需要在其他地方调用该函数,问题是我不知道在哪里。谢谢。


The function is supposed to change the code of an select tag in 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 the function elsewhere,the problem is that I do not know where. Thank you.

推荐答案


这篇关于为什么OuterHTML功能会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 09:29
查看更多