PersistChildrenAttribute.UsesCustomPersistence Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value indicating whether the server control provides custom persistence of nested controls at design time.
public:
property bool UsesCustomPersistence { bool get(); };
public bool UsesCustomPersistence { get; }
member this.UsesCustomPersistence : bool
Public ReadOnly Property UsesCustomPersistence As Boolean
Property Value
true
to provide custom persistence of nested content; otherwise, false
. The default is false
.
Examples
The following code example demonstrates how to get the value of the UsesCustomPersistence property.
This code example is part of a larger example provided for the PersistChildrenAttribute class.
<%@ Page Language="C#" %>
<%@ Register TagPrefix="AspSample" Assembly="Samples.AspNet.CS.Controls" Namespace="PersistChildrenSamples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
// Create two new employees and add them to the custom control.
Employee e1 = new Employee("Employee 1", "Title 1", "Alias 1");
Employee e2 = new Employee("Employee 2", "Title 2", "Alias 2");
CollectionPropertyControl1.Employees.Add(e1);
CollectionPropertyControl1.Employees.Add(e2);
// Verify attribute values.
PersistChildrenAttribute p =
(PersistChildrenAttribute)Attribute.GetCustomAttribute(typeof(CollectionPropertyControl),
typeof(PersistChildrenAttribute));
StringBuilder sb = new StringBuilder();
sb.Append("The Persist property is " + p.Persist.ToString() + "<br />");
sb.Append("The UseCustomPersistence property is " + p.UsesCustomPersistence.ToString() + "<br />");
sb.Append("The IsDefault method returns " + p.IsDefaultAttribute().ToString());
Message.Text = sb.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>PersistChildrenAttribute</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Message"
runat="server"/>
<AspSample:CollectionPropertyControl id="CollectionPropertyControl1"
runat="server">
</AspSample:CollectionPropertyControl>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="AspSample" Assembly="Samples.AspNet.VB.Controls" Namespace="PersistChildrenSampleVB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Create two new employees and add them to the custom control.
Dim e1 As New Employee("Employee 1", "Title 1", "Alias 1")
Dim e2 As New Employee("Employee 2", "Title 2", "Alias 2")
CollectionPropertyControl1.Employees.Add(e1)
CollectionPropertyControl1.Employees.Add(e2)
' Verify attribute values.
Dim p As PersistChildrenAttribute = _
Attribute.GetCustomAttribute(GetType(CollectionPropertyControl), _
GetType(PersistChildrenAttribute))
Dim sb As New StringBuilder()
sb.Append("The Persist property is " & p.Persist.ToString() & "<br />")
sb.Append("The UseCustomPersistence property is " & p.UsesCustomPersistence.ToString() & "<br />")
sb.Append("The IsDefault method returns " & p.IsDefaultAttribute().ToString())
Message.Text = sb.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PersistChildrenAttribute</title>
</head>
<body>
<form id="Form1" runat="server">
<div>
<asp:Label ID="Message"
runat="server"/>
<AspSample:CollectionPropertyControl id="CollectionPropertyControl1"
runat="server">
</AspSample:CollectionPropertyControl>
</div>
</form>
</body>
</html>
Remarks
To configure nested content for custom persistence, use the PersistChildrenAttribute overload that takes a usesCustomPersistence
parameter.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기