デザイン時に、ASP.NET サーバー コントロールの子コントロールが、入れ子になった内部コントロールとして永続化されるかどうかを示す値を取得します。
Public ReadOnly Property Persist As Boolean
[C#]
public bool Persist {get;}
[C++]
public: __property bool get_Persist();
[JScript]
public function get Persist() : Boolean;
プロパティ値
子コントロールが、入れ子になった内部コントロールとして永続化される場合は true 。それ以外の場合は false 。
使用例
' Use the PersistChildren attribute to set the Persist
' property to false so that none of this class's
' child controls will be persisted as controls. They will
' be persisted only as child elements of this class.
' If you set the PersistChildren attribute to true, or if you
' do not include this attribute when you create a control,
' the child controls will be persisted as controls.
<PersistChildren(False)> _
Public Class CollectionPropertyControl
Inherits Control
Private _header As String
Private _employees As New ArrayList()
Public Property Header() As String
Get
Return _header
End Get
Set
_header = value
End Set
End Property
Public ReadOnly Property Employees() As ArrayList
Get
Return _employees
End Get
End Property
' Override the CreateChildControls method to
' add child controls to the Employees property when this
' custom control is requested from a page.
Protected Overrides Sub CreateChildControls()
Dim label As New Label()
label.Text = Header
label.BackColor = Color.Beige
label.ForeColor = Color.Red
Controls.Add(label)
Controls.Add(New LiteralControl("<BR> <BR>"))
Dim table As New Table()
Dim htr As New TableRow()
Dim hcell1 As New TableHeaderCell()
hcell1.Text = "Name"
htr.Cells.Add(hcell1)
Dim hcell2 As New TableHeaderCell()
hcell2.Text = "Title"
htr.Cells.Add(hcell2)
Dim hcell3 As New TableHeaderCell()
hcell3.Text = "Alias"
htr.Cells.Add(hcell3)
table.Rows.Add(htr)
table.BorderWidth = Unit.Pixel(2)
table.BackColor = Color.Beige
table.ForeColor = Color.Red
Dim employee As Employee
For Each employee In Employees
Dim tr As New TableRow()
Dim cell1 As New TableCell()
cell1.Text = employee.Name
tr.Cells.Add(cell1)
Dim cell2 As New TableCell()
cell2.Text = employee.Title
tr.Cells.Add(cell2)
Dim cell3 As New TableCell()
cell3.Text = employee.Alias
tr.Cells.Add(cell3)
table.Rows.Add(tr)
Next employee
Controls.Add(table)
End Sub 'CreateChildControls
End Class 'CollectionPropertyControl
[C#]
// Use the PersistChildren attribute to set the Persist
// property to false so that none of this class's
// child controls will be persisted as controls. They will
// be persisted only as child elements of this class.
// If you set the PersistChildren attribute to true, or if you
// do not include this attribute when you create a control,
// the child controls will be persisted as controls.
[PersistChildren(false)]
public class CollectionPropertyControl : Control
{
private String header;
private ArrayList employees = new ArrayList();
public String Header
{
get
{
return header;
}
set
{
header = value;
}
}
public ArrayList Employees
{
get
{
return employees;
}
}
// Override the CreateChildControls method to
// add child controls to the Employees property when this
// custom control is requested from a page.
protected override void CreateChildControls()
{
Label label = new Label();
label.Text = Header;
label.BackColor = Color.Beige;
label.ForeColor = Color.Red;
Controls.Add(label);
Controls.Add(new LiteralControl("<BR> <BR>"));
Table table = new Table();
TableRow htr = new TableRow();
TableHeaderCell hcell1 = new TableHeaderCell();
hcell1.Text = "Name";
htr.Cells.Add(hcell1);
TableHeaderCell hcell2 = new TableHeaderCell();
hcell2.Text = "Title";
htr.Cells.Add(hcell2);
TableHeaderCell hcell3 = new TableHeaderCell();
hcell3.Text = "Alias";
htr.Cells.Add(hcell3);
table.Rows.Add(htr);
table.BorderWidth = 2;
table.BackColor = Color.Beige;
table.ForeColor = Color.Red;
foreach (Employee employee in Employees)
{
TableRow tr = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = employee.Name;
tr.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Text = employee.Title;
tr.Cells.Add(cell2);
TableCell cell3 = new TableCell();
cell3.Text = employee.Alias;
tr.Cells.Add(cell3);
table.Rows.Add(tr);
}
Controls.Add(table);
}
}
[C++]
// Use the PersistChildren attribute to set the Persist
// property to false so that none of this class's
// child controls will be persisted as controls. They will
// be persisted only as child elements of this class.
// If you set the PersistChildren attribute to true, or if you
// do not include this attribute when you create a control,
// the child controls will be persisted as controls.
[PersistChildren(false)]
public __gc class CollectionPropertyControl : public Control {
private:
String* header;
private:
ArrayList* employees;
public:
CollectionPropertyControl()
{
employees = new ArrayList();
}
__property String* get_Header() {
return header;
}
__property void set_Header(String* value) {
header = value;
}
public:
__property ArrayList* get_Employees() {
return employees;
}
// Override the CreateChildControls method to
// add child controls to the Employees property when this
// custom control is requested from a page.
protected:
void CreateChildControls() {
Label* label = new Label();
label->Text = Header;
label->BackColor = Color::Beige;
label->ForeColor = Color::Red;
Controls->Add(label);
Controls->Add(new LiteralControl(S"<BR> <BR>"));
Table* table = new Table();
TableRow* htr = new TableRow();
TableHeaderCell* hcell1 = new TableHeaderCell();
hcell1->Text = S"Name";
htr->Cells->Add(hcell1);
TableHeaderCell* hcell2 = new TableHeaderCell();
hcell2->Text = S"Title";
htr->Cells->Add(hcell2);
TableHeaderCell* hcell3 = new TableHeaderCell();
hcell3->Text = S"Alias";
htr->Cells->Add(hcell3);
table->Rows->Add(htr);
table->BorderWidth = 2;
table->BackColor = Color::Beige;
table->ForeColor = Color::Red;
IEnumerator* myEnum = Employees->GetEnumerator();
while (myEnum->MoveNext()) {
Employee* employee = __try_cast<Employee*>(myEnum->Current);
TableRow* tr = new TableRow();
TableCell* cell1 = new TableCell();
cell1->Text = employee->Name;
tr->Cells->Add(cell1);
TableCell* cell2 = new TableCell();
cell2->Text = employee->Title;
tr->Cells->Add(cell2);
TableCell* cell3 = new TableCell();
cell3->Text = employee->Alias;
tr->Cells->Add(cell3);
table->Rows->Add(tr);
}
Controls->Add(table);
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
PersistChildrenAttribute クラス | PersistChildrenAttribute メンバ | System.Web.UI 名前空間