共用方式為


AttributeCollection.Remove(String) 方法

定義

從伺服器控制項的 AttributeCollection 物件移除屬性。

public:
 void Remove(System::String ^ key);
public void Remove (string key);
member this.Remove : string -> unit
Public Sub Remove (key As String)

參數

key
String

要移除的屬性名稱。

範例

下列範例示範如何以程式設計方式從 HTML 伺服器控制項的物件 AttributeCollection 中移除屬性。

<%@ Page Language="C#" %>

<!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 SubmitBtn_Click(object sender, EventArgs e)
    {
        FirstSelect.Attributes.Remove("Size");
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>
</head>

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="FirstSelect"
            size="10"
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="SubmitBtn"
           value="Remove Size Attribute" 
           onserverclick="SubmitBtn_Click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>
<%@ Page Language="VB" %>

<!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 SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FirstSelect.Attributes.Remove("Size")
    End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>
</head>

 <body>
    <form id="form1" runat="server">
    <div>
    Make a selection:
    <select id="FirstSelect"
            size="10"
            runat="server">
       <option>This</option>
       <option>That</option>
       <option>Other</option>
    </select>
    <br/><br/>

    <input type="submit" 
           id="SubmitBtn"
           value="Remove Size Attribute" 
           onserverclick="SubmitBtn_Click" 
           runat="server"/>
    </div>
 </form>
 </body>
 </html>

備註

AttributeCollection如果 物件不包含具有指定 key 之 的屬性,集合會保持不變。 不會擲回任何例外狀況。

適用於

另請參閱