复合控件中的面板忽略可见性

发布于 2024-11-17 10:56:33 字数 872 浏览 6 评论 0原文

我正在构建一个复合控件,它根据指定的状态在页面上呈现 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);

无论初始化期间的可见性检查如何,这基本上仍然显示面板。我测试了各种不同的场景,由于某种原因,这个场景只是忽略了状态。有什么想法吗?

谢谢,

埃里克

I'm building a composite control that renders HTML on a page based on a specified state.

If I set up the control, and add it to the ControlCollection for composite, and set the visibility of the control during set up to false it seems to be working fine, the panel is hidden until a postback on the page causes the panel to be displayed.

But, when I wrap a RenderBeginTag(writer) and RenderEndTag(writer) in the Render method, it seems to be ignoring the "visible = false" statement during initialization?

// 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);

This basically still displays the panel, regardless of the visibility check during initialization. I've tested various different scenarios, and for some reason this one just ignores the state. Any ideas?

Thanks,

Eric

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随波逐流 2024-11-24 10:56:33

Visible 标志确定控件是否在服务器上呈现。因此,当您在 CreateChildControls 期间添加控件时,ASP 将检查 Visible 标志并在 Render() 期间跳过该控件。然而,当您调用 RenderBeginTag 时,您实际上忽略了 Visible 标志。

如果您想将控件 HTML 呈现给客户端,但将 div 隐藏起来,那么您应该将 display CSS 属性设置为 none。

例如

this._contentPanel.ID = "ContentPanel";
this._contentPanel.Visible = false;
this._contentPanel.Style["display"] = "none";

The Visible flag determines whether the control is rendered on the server. Therefore when you add the control during CreateChildControls ASP will check the Visible flag and skip the control during Render(). However when you call RenderBeginTag you are effectively ignoring the Visible flag.

If you want to render the controls HTML to the client but keep it the div hidden then you should set the display CSS attribute to none.

e.g.

this._contentPanel.ID = "ContentPanel";
this._contentPanel.Visible = false;
this._contentPanel.Style["display"] = "none";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文