请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
System.Web.UI
Control 类
Control 方法
 EnsureChildControls 方法

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
Control.EnsureChildControls 方法

确定服务器控件是否包含子控件。如果不包含,则创建子控件。

命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)

Visual Basic(声明)
Protected Overridable Sub EnsureChildControls
Visual Basic(用法)
Me.EnsureChildControls
C#
protected virtual void EnsureChildControls ()
C++
protected:
virtual void EnsureChildControls ()
J#
protected void EnsureChildControls ()
JScript
protected function EnsureChildControls ()

该方法首先检查 ChildControlsCreated 属性的当前值。如果此值为假,则调用 CreateChildControls 方法。

当 ASP.NET 需要确保已创建子控件时,它将调用该方法。大多数情况下,自定义服务器控件的开发人员无需重写此方法。如果确实重写了此方法,请按与其默认行为相似的方式来使用。

下面的示例使用 EnsureChildControls 方法确保当前服务器控件具有子控件。然后它获取或设置当前服务器控件的 ControlCollection 对象中子 TextBoxWeb 控件的 Text 属性。

Visual Basic
' Ensure the current control has children,
' then get or set the Text property.

Public Property Value() As Integer
   Get
      Me.EnsureChildControls()
      Return Int32.Parse(CType(Controls(1), TextBox).Text)
   End Get
   Set
      Me.EnsureChildControls()
      CType(Controls(1), TextBox).Text = value.ToString()
   End Set
End Property


C#
// Ensure the current control has children,
// then get or set the Text property.
 public int Value {
    get {
        this.EnsureChildControls();
        return Int32.Parse(((TextBox)Controls[1]).Text);
    }
    set {
        this.EnsureChildControls();
        ((TextBox)Controls[1]).Text = value.ToString();
    }
 }

J#
// Ensure the current control has children,
// then get or set the Text property.
/** @property 
 */
public int get_Value()
{
    this.EnsureChildControls();
    return Int32.Parse(((TextBox)(get_Controls().get_Item(1))).get_Text());
} //get_Value

/** @property 
 */
public void set_Value(int value)
{
    this.EnsureChildControls();
    ((TextBox)get_Controls().get_Item(1)).set_Text(((Int32)value).ToString());
} //set_Value
JScript
// Ensure the current control has children,
// then get or set the Text property.
 public function get Value() : int
 {
       this.EnsureChildControls();
       return Int32.Parse(TextBox(Controls[1]).Text);
 }

 public function set Value(value : int)
 {
        this.EnsureChildControls();
        TextBox(Controls[1]).Text = value.ToString();
 }

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0、1.1、1.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker