AttributeCollection Classe
Definição
Fornece acesso de modelo de objeto a todos os atributos declarados na marca de abertura de um elemento de controle de servidor ASP.NET.Provides object-model access to all attributes declared in the opening tag of an ASP.NET server control element. Essa classe não pode ser herdada.This class cannot be inherited.
public ref class AttributeCollection sealed
public sealed class AttributeCollection
type AttributeCollection = class
Public NotInheritable Class AttributeCollection
- Herança
-
AttributeCollection
Exemplos
O exemplo a seguir cria um novo AttributeCollection objeto chamado myAttributeCollection e, em seguida, verifica se a página foi postada de volta.The following example creates a new AttributeCollection object that is named myAttributeCollection, and then checks whether the page has been posted back. Se não tiver, o código adicionará dois atributos à coleção.If it has not, the code adds two attributes to the collection. Em seguida, ele obtém o número de atributos na coleção e itera na coleção, gravando a chave em cada atributo na página.It then gets the number of attributes in the collection and iterates through the collection, writing the key to each attribute to the page. Se a página for um postback, o código obterá o novo número de atributos e iterará pela coleção, gravando a chave e o valor de cada atributo na página.If the page is a postback, the code gets the new number of attributes and iterates through the collection, writing the key and value of each attribute to the page.
AttributeCollection myAttributeCollection = null;
void Page_Load(object sender,EventArgs e)
{
myAttributeCollection = new AttributeCollection(ViewState);
Response.Write("<h3> AttributeCollection.AttributeCollection Sample </h3>");
if (!IsPostBack)
{
myAttributeCollection.Add("Color" ,"Color.Red");
myAttributeCollection.Add("BackColor","Color.blue");
Response.Write("Attribute Collection count before PostBack = " + myAttributeCollection.Count);
Response.Write("<br /><u><h4>Enumerating Attributes for CustomControl before PostBack</h4></u>");
IEnumerator keys = myAttributeCollection.Keys.GetEnumerator();
int i =1;
String key;
while (keys.MoveNext())
{
key = (String)keys.Current;
Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br />");
i++;
}
}
else
{
Response.Write("Attribute Collection count after PostBack = "+myAttributeCollection.Count);
Response.Write("<br /><u><h4>Enumerating Attributes for CustomControl after PostBack</h4></u>");
IEnumerator keys = myAttributeCollection.Keys.GetEnumerator();
int i =1;
String key;
while (keys.MoveNext())
{
key = (String)keys.Current;
Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br />");
i++;
}
}
}
Dim myAttributeCollection As AttributeCollection = Nothing
Sub Page_Load(sender As Object, e As EventArgs)
myAttributeCollection = New AttributeCollection(ViewState)
Response.Write("<h3> AttributeCollection.AttributeCollection Sample </h3>")
If Not IsPostBack Then
myAttributeCollection.Add("Color", "Color.Red")
myAttributeCollection.Add("BackColor", "Color.blue")
Response.Write("Attribute Collection count before PostBack = " & _
myAttributeCollection.Count.ToString())
Response.Write("<br /><u><h4>Enumerating Attributes for " & _
"CustomControl before PostBack</h4></u>")
Dim keys As IEnumerator = myAttributeCollection.Keys.GetEnumerator()
Dim i As Integer = 1
Dim key As String
While keys.MoveNext()
key = CType(keys.Current, String)
Response.Write(i.ToString() + ". " + key + "=" + myAttributeCollection(key) + "<br />")
i += 1
End While
Else
Response.Write("Attribute Collection count after PostBack = " + _
myAttributeCollection.Count.ToString())
Response.Write("<br /><u><h4>Enumerating Attributes for " + _
"CustomControl after PostBack</h4></u>")
Dim keys As IEnumerator = myAttributeCollection.Keys.GetEnumerator()
Dim i As Integer = 1
Dim key As String
While keys.MoveNext()
key = CType(keys.Current, String)
Response.Write(i.ToString() + ". " + key + "=" + myAttributeCollection(key) + "<br />")
i += 1
End While
End If
End Sub
Comentários
Os itens individuais na coleção retornam um String objeto como seu valor.Individual items in the collection return a String object as their value. Se não houver nenhum item de atributo na coleção, a coleção retornará null .If there are no attribute items in the collection, the collection returns null.
Os atributos em um controle de servidor HTML estão programaticamente disponíveis por meio da Attributes propriedade, que é herdada por todos os controles de servidor HTML.Attributes on an HTML server control are programmatically available through the Attributes property, which is inherited by all HTML server controls. ASP.NET expõe atributos de controles de servidor HTML como propriedades desses controles.ASP.NET exposes attributes of HTML server controls as properties of those controls.
Você pode adicionar atributos a um controle de servidor Web por meio da Attributes propriedade, que é herdada por todos os controles de servidor Web.You can add attributes to a Web server control through the Attributes property, which is inherited by all Web server controls. Os atributos na coleção Attributes de um controle de servidor Web não correspondem necessariamente às propriedades fortemente tipadas do controle para esse controle.The attributes in the attributes collection for a Web server control do not necessarily correspond to the control's strongly typed properties for that control.
Construtores
| AttributeCollection(StateBag) |
Inicializa uma nova instância da classe AttributeCollection.Initializes a new instance of the AttributeCollection class. |
Propriedades
| Count |
Obtém o número de atributos no objeto AttributeCollection.Gets the number of attributes in the AttributeCollection object. |
| CssStyle |
Obtém uma coleção de estilos para o controle de servidor ASP.NET ao qual o objeto AttributeCollection atual pertence.Gets a collection of styles for the ASP.NET server control to which the current AttributeCollection object belongs. |
| Item[String] |
Obtém ou define um valor de atributo especificado para um controle de servidor.Gets or sets a specified attribute value for a server control. |
| Keys |
Obtém uma coleção de chaves para todos os atributos no objeto AttributeCollection do controle do servidor.Gets a collection of keys to all attributes in the server control's AttributeCollection object. |
Métodos
| Add(String, String) |
Adiciona um atributo a um objeto AttributeCollection de controle de servidor.Adds an attribute to a server control's AttributeCollection object. |
| AddAttributes(HtmlTextWriter) |
Adiciona atributos da classe AttributeCollection ao objeto HtmlTextWriter que é responsável por processar os atributos como marcação.Adds attributes from the AttributeCollection class to the HtmlTextWriter object that is responsible for rendering the attributes as markup. |
| Clear() |
Remove todos os atributos de um objeto AttributeCollection do controle de servidor.Removes all attributes from a server control's AttributeCollection object. |
| Equals(Object) |
Determina se a instância atual do objeto AttributeCollection é igual ao objeto especificado.Determines whether the current instance of the AttributeCollection object is equal to the specified object. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| Remove(String) |
Remove um atributo de um objeto AttributeCollection do controle de servidor.Removes an attribute from a server control's AttributeCollection object. |
| Render(HtmlTextWriter) |
Grava a coleção de atributos no fluxo de saída HtmlTextWriter especificado para o controle ao qual a coleção pertence.Writes the collection of attributes to the specified HtmlTextWriter output stream for the control to which the collection belongs. |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |