IStyleSheet.CreateStyleRule(Style, IUrlResolutionService, String) Méthode

Définition

En cas d'implémentation dans une classe, crée une règle de style pour le type de l'élément de langage de document spécifié, ou sélecteur.

public:
 void CreateStyleRule(System::Web::UI::WebControls::Style ^ style, System::Web::UI::IUrlResolutionService ^ urlResolver, System::String ^ selector);
public void CreateStyleRule (System.Web.UI.WebControls.Style style, System.Web.UI.IUrlResolutionService urlResolver, string selector);
abstract member CreateStyleRule : System.Web.UI.WebControls.Style * System.Web.UI.IUrlResolutionService * string -> unit
Public Sub CreateStyleRule (style As Style, urlResolver As IUrlResolutionService, selector As String)

Paramètres

style
Style

Règle de style à ajouter à la feuille de style incorporée.

urlResolver
IUrlResolutionService

Objet implémentant IUrlResolutionService qui contient les informations de contexte relatives à l'emplacement (URL) actuel.

selector
String

Partie de la page HTML affectée par le style.

Exemples

L’exemple de code suivant utilise l’implémentation Header de IStyleSheet pour illustrer la définition d’un nouvel Style objet, bodyStyle. Est ensuite bodyStyle ajouté à l’URL actuelle en appelant CreateStyleRule.

<%@ 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">

  void Page_Load(object sender, EventArgs e)
  {
    if (Page.Header != null)
    {
      // Create a Style object for the <body> section of the Web page.
      Style bodyStyle = new Style();

      bodyStyle.ForeColor = System.Drawing.Color.Blue;
      bodyStyle.BackColor = System.Drawing.Color.LightGray;

      // Add the style to the header of the current page.
      Page.Header.StyleSheet.CreateStyleRule(bodyStyle, this, "BODY");

      // Add text to the label2 control to see the style rules applied to it.
      label1.Text = "This is what the bodyStyle looks like.";
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>    
<body>
    <form id="form1" runat="server">
        <h1>IStyleSheet Example</h1>
        <asp:Label 
          id="label1" 
          runat="server">
        </asp:Label>
    </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">
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  
    If Not Page.Header Is Nothing Then
    
      ' Create a Style object for the <body> section of the Web page.
      Dim bodyStyle As Style = New Style()

      bodyStyle.ForeColor = System.Drawing.Color.Blue
      bodyStyle.BackColor = System.Drawing.Color.LightGray

      ' Add the style to the header of the current page.
      Page.Header.StyleSheet.CreateStyleRule(bodyStyle, me, "BODY")

      ' Add text to the label2 control to see the style rules applied to it.
      label1.Text = "This is what the bodyStyle looks like."
      
    End If
    
  End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>    
<body>
    <form id="form1" runat="server">
        <h1>IStyleSheet Example</h1>
        <asp:Label 
          id="label1" 
          runat="server">
        </asp:Label>
    </form>
  </body>
</html>

Remarques

La CreateStyleRule méthode crée une règle de style pour le sélecteur spécifié. Plusieurs règles de style peuvent être créées pour le même sélecteur.

Si urlResolver a la valeur null, l’URL de l’instance actuelle Page est utilisée.

Notes

L’ajout ou la modification de styles ou de règles de style par programmation pendant les publications asynchrones n’est pas pris en charge. Lorsque vous ajoutez des fonctionnalités AJAX à une page web ASP.NET, les publications asynchrones mettent à jour les régions de la page sans mettre à jour la page entière. Pour plus d’informations, consultez Microsoft Vue d’ensemble d’Ajax.

S’applique à