设置父控件的启用属性时会发生什么?

时间:2022-08-21 15:19:18

I have a container of custom controls each of which have 2 controls in them. One to display when enabled (i.e. a textbox, or checkbox), and a label to display when disabled.

我有一个自定义控件的容器,每个控件都有2个控件。一个在启用时显示(即文本框或复选框),以及禁用时显示的标签。

I've overloaded Render like so:

我像这样重载了Render:

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        If Me.Enabled Then
            _item.RenderControl(writer)
        Else
            _display_text.RenderControl(writer)
        End If
    End Sub

however, when I set the container, which is a table, to Enabled = False, my expected functionality doesn't happen. Instead I get grayed out textboxes and checkboxes.

但是,当我将容器(即表)设置为Enabled = False时,我的预期功能不会发生。相反,我变灰了文本框和复选框。

What actually happens when you set a parent's Enabled property? My assumption was that it propagated that status down to all its children, but it appears that I'm mistaken.

设置父级的Enabled属性时实际发生了什么?我的假设是它将这种状态传播给了它的所有孩子,但似乎我错了。

Thank you!

1 个解决方案

#1


Short answer is that your assumption is actually wrong.

简短的回答是你的假设实际上是错误的。

If you like (and are extending WebControl, and your container has a runat=server), you could use

如果你喜欢(并且正在扩展WebControl,并且你的容器有一个runat = server),你可以使用

If NamingContainer.Enabled Then

instead of

If Me.Enabled Then

but properties do not auto propagate down the the tree in asp.

但属性不会在asp中自动传播到树中。

#1


Short answer is that your assumption is actually wrong.

简短的回答是你的假设实际上是错误的。

If you like (and are extending WebControl, and your container has a runat=server), you could use

如果你喜欢(并且正在扩展WebControl,并且你的容器有一个runat = server),你可以使用

If NamingContainer.Enabled Then

instead of

If Me.Enabled Then

but properties do not auto propagate down the the tree in asp.

但属性不会在asp中自动传播到树中。