Export (0) Print
Expand All

CssStyleCollection.Remove Method (String)

Removes a style item from the CssStyleCollection of a control using the specified style key.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public void Remove(
	string key
)

Parameters

key
Type: System.String
The string literal of the style item to remove.

The following example demonstrates how to use the Remove method to programmatically delete a CSS style from an HtmlSelect control.


<%@ 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.Style.Remove("font");
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssStyleCollection Remove Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Click the submit button to clear the font formatting.
    <br />
    <select id="FirstSelect" 
            style="font: 14pt Arial; background-color:Yellow; color:Blue;"
            runat="server">
        <option >option 1</option>
        <option >option 2</option>
        <option >option 3</option>
    </select> 
    <input id="SubmitBtn" 
           value="Submit" 
           type="submit" 
           onserverclick="SubmitBtn_Click"
           runat="server" /><br />
    </div>
    </form>
</body></html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft