简体   繁体   中英

Why is RenderControl called when a Control's Visible property is set to false?

I've put a breakpoint on my Control's overridden RenderControl method and the breakpoint is being hit, but in Visual Studio, I can see that this.Visible is false .

In the documentation for the Visible property it says:

If this property is false, the server control is not rendered.

This doesn't necessarily mean the RenderControl method is not called, but it's a big hint that it shouldn't do. Should I be jumping out of the method manually if Visible is false? Is this documented anywhere?

Accorging to msdn :

Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control , providing a text writer that writes its output to the OutputStream object of the page's Response property.

And as you can see from the diagramm below, RenderControl is a part of Render process: 在此输入图像描述

So it call the method RenderControl regardless Visible prop value. It's your responsibility to output empty string or anything based on Visible property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM