我正在构建一个复合控件,该控件根据指定的状态在页面上呈现HTML。
如果我设置了控件,并将其添加到用于复合的ControlCollection
中,并在设置期间将控件的可见性设置为false
,则它似乎工作正常,面板将被隐藏,直到页面上的回发导致面板显示为止。
但是,当我在Render
方法中包装RenderBeginTag(writer)
和RenderEndTag(writer)
时,它似乎在初始化期间忽略了"visible = false
"语句?
// initialization
this._contentPanel = new Panel();
this._contentPanel.ID = "ContentPanel";
this._contentPanel.Visible = false;
this.Controls.Add(this._contentPanel);
// CreateChildControls
this.InitContentPanel(); // adds the content panel to control collection
// render
this._contentPanel.RenderBeginTag(writer);
writer.WriteLine("<div>Some copy here</div>");
this._contentPanel.RenderEndTag(writer);
这基本上仍然显示面板,而不考虑初始化期间的可见性检查。我测试了各种不同的场景,出于某种原因,这个场景忽略了状态。有什么想法吗?
谢谢,
Eric
如果您想将控件HTML呈现给客户端,但保持div隐藏,那么您应该将display CSS属性设置为none。
例如
this._contentPanel.ID = "ContentPanel";
this._contentPanel.Visible = false;
this._contentPanel.Style["display"] = "none";