PersistChildrenAttribute.UsesCustomPersistence Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um valor que indica se o controle do servidor oferece persistência personalizada de controles aninhados no tempo de design.
public:
property bool UsesCustomPersistence { bool get(); };
public bool UsesCustomPersistence { get; }
member this.UsesCustomPersistence : bool
Public ReadOnly Property UsesCustomPersistence As Boolean
Valor da propriedade
true
para fornecer persistência personalizada de conteúdo aninhado; caso contrário, false
. O padrão é false
.
Exemplos
O exemplo de código a seguir demonstra como obter o valor da UsesCustomPersistence propriedade .
Este exemplo de código faz parte de um exemplo maior fornecido para a PersistChildrenAttribute classe .
<%@ 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>
Comentários
Para configurar o conteúdo aninhado para persistência personalizada, use a PersistChildrenAttribute sobrecarga que usa um usesCustomPersistence
parâmetro .