我有这段代码
var anchor = new HtmlAnchor {HRef = temp, InnerText = this.LinkDescription};
anchor.Attributes.Add("class", "navActive back");
anchor.ServerClick += new EventHandler(AnchorServerClick);
writer.Write("<div id=\"leftnav\"><ul><li>");
anchor.RenderControl(writer);
writer.Write("</li></ul></div>");
在自定义 Web 控件中。我在 anchor.RenderControl 处收到 nullReference 异常,为什么?我调试了上面的,作者也不为空,锚也不。那里发生了什么事?谢谢!
编辑:我正在添加堆栈跟踪以进行调试
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.UI.HtmlControls.HtmlAnchor.GetPostBackOptions() +107
System.Web.UI.HtmlControls.HtmlAnchor.RenderAttributes(HtmlTextWriter writer) +10975634
System.Web.UI.HtmlControls.HtmlControl.RenderBeginTag(HtmlTextWriter writer) +56
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +26
CER.Portal.Dashboard.Controls.BackLink.Render(HtmlTextWriter writer) +1151