开发者

Conditionally render a control in a webpage

For example what if I am trying to hide a custom navigation control what can I place in another webcontrol to 开发者_运维知识库conditionally hide the label something like this

   <mycontrol:hidethis id=mycontrol1 runat="server">
          <mycontrol:mynavi runat="server"/>
    </mycontrol:hidethis>

Thanks


Your question is wide open, there could be a few ways to hide your control.

One very simple way to do it is in the PreRender of the navigation control's parent - just set the Visible property of the nav control to false (if the right conditions are met). If coded correctly (i have to say that, sometimes people code stupidly :) then the Visible property will be propagated to all the child controls of the nav control, and none of them will get rendered to the output stream.


Why don't you add a property to the control which says Visible and you internally set the control as visible true/ false.


Have a look at

protected override void AddParsedSubObject(object obj)
{

}

That should be the right place to say wether subcontrols should be rendered or not

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜