Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
RouteParameter, classe
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
RouteParameter Class

Binds the value of a URL segment to a parameter object.

System..::.Object
  System.Web.UI.WebControls..::.Parameter
    System.Web.UI.WebControls..::.RouteParameter

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Class RouteParameter _
    Inherits Parameter
C#
public class RouteParameter : Parameter
Visual C++
public ref class RouteParameter : public Parameter
F#
type RouteParameter =  
    class
        inherit Parameter
    end

The RouteParameter type exposes the following members.

  NameDescription
Public methodRouteParameter()()()Initializes a new instance of the RouteParameter class.
Protected methodRouteParameter(RouteParameter)Initializes a new instance of the RouteParameter class by using the values of the specified instance.
Public methodRouteParameter(String, String)Initializes a new instance of the RouteParameter class by using the specified name for the parameter and the specified key for route data.
Public methodRouteParameter(String, DbType, String)Initializes a new instance of the RouteParameter class by using the specified name and database type for the parameter, and by using the specified key for the route data.
Public methodRouteParameter(String, TypeCode, String)Initializes a new instance of the RouteParameter class by using the specified name and type for the parameter, and by using the specified key for the route data.
Top
  NameDescription
Public propertyConvertEmptyStringToNullGets or sets a value indicating whether the value that the Parameter object is bound to should be converted to nullNothingnullptra null reference (Nothing in Visual Basic) if it is String..::.Empty. (Inherited from Parameter.)
Public propertyDbTypeGets or sets the database type of the parameter. (Inherited from Parameter.)
Public propertyDefaultValueSpecifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate method is called. (Inherited from Parameter.)
Public propertyDirectionIndicates whether the Parameter object is used to bind a value to a control, or the control can be used to change the value. (Inherited from Parameter.)
Protected propertyIsTrackingViewStateGets a value indicating whether the Parameter object is saving changes to its view state. (Inherited from Parameter.)
Public propertyNameGets or sets the name of the parameter. (Inherited from Parameter.)
Public propertyRouteKeyGets or sets the name of the route segment from which to retrieve the value for the route parameter.
Public propertySizeGets or sets the size of the parameter. (Inherited from Parameter.)
Public propertyTypeGets or sets the type of the parameter. (Inherited from Parameter.)
Protected propertyViewStateGets a dictionary of state information that allows you to save and restore the view state of a Parameter object across multiple requests for the same page. (Inherited from Parameter.)
Top
  NameDescription
Protected methodCloneReturns a duplicate of the current RouteParameter instance. (Overrides Parameter..::.Clone()()().)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodEvaluateEvaluates the request URL and returns the value of the parameter. (Overrides Parameter..::.Evaluate(HttpContext, Control).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetDatabaseTypeGets the DbType value that is equivalent to the CLR type of the current Parameter instance. (Inherited from Parameter.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodLoadViewStateRestores the data source view's previously saved view state. (Inherited from Parameter.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnParameterChangedCalls the OnParametersChanged method of the ParameterCollection collection that contains the Parameter object. (Inherited from Parameter.)
Protected methodSaveViewStateSaves the changes to the Parameter object's view state since the time the page was posted back to the server. (Inherited from Parameter.)
Protected methodSetDirtyMarks the Parameter object so its state will be recorded in view state. (Inherited from Parameter.)
Public methodToStringConverts the value of this instance to its equivalent string representation. (Inherited from Parameter.)
Protected methodTrackViewStateCauses the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page. (Inherited from Parameter.)
Top
  NameDescription
Explicit interface implemetationPrivate methodICloneable..::.CloneReturns a duplicate of the current Parameter instance. (Inherited from Parameter.)
Explicit interface implemetationPrivate propertyIStateManager..::.IsTrackingViewStateInfrastructure. Gets a value indicating whether the Parameter object is saving changes to its view state. (Inherited from Parameter.)
Explicit interface implemetationPrivate methodIStateManager..::.LoadViewStateInfrastructure. Restores the data source view's previously saved view state. (Inherited from Parameter.)
Explicit interface implemetationPrivate methodIStateManager..::.SaveViewStateInfrastructure. Saves the changes to the Parameter object's view state since the time the page was posted back to the server. (Inherited from Parameter.)
Explicit interface implemetationPrivate methodIStateManager..::.TrackViewStateInfrastructure. Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page. (Inherited from Parameter.)
Top

If you implement ASP.NET routing in a Web site, you can use the RouteParameter object to bind the value of a segment of the requested URL to a database query or command. You can declare RouteParameter objects in markup for data source controls or the QueryExtender control.

A Visual Studio Web site project with source code is available to accompany this topic: Download.

The examples in this section show how to use RouteParameter objects in markup to pass URL parameter values to a query that is specified for a data source control.

The following example shows code in the Global.asax page that defines a route that is named ProductRoute. The route defines a URL parameter that is named productname. The route also defines an optional catchall parameter that is named culture, which can be used to specify the language in which the product description is displayed. The Product.aspx page handles requests for this route.

The following example shows the Product.aspx page. The page contains a SqlDataSource control that has a query that requires two parameters, one for the name of the product and one for the language of the product description. RouteParameter objects are used to supply the values for the query parameters. The value of the route URL parameter productname is passed to the query parameter @productname. The value of the route URL parameter culture is passed to the query parameter @culture. If a route URL does not include the URL parameter culture, a default value of "en" is used.

None
<%@ Page %>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html >
<head runat="server">
    <title>Product Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Product Page</h1>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorksLTConnectionString %>" 
            SelectCommand="SELECT SalesLT.Product.ProductID, 
                SalesLT.Product.Name, 
                SalesLT.ProductDescription.Description 
                FROM SalesLT.Product 
                INNER JOIN SalesLT.ProductModel 
                ON SalesLT.Product.ProductModelID = 
                SalesLT.ProductModel.ProductModelID 
                INNER JOIN SalesLT.ProductModelProductDescription 
                ON SalesLT.ProductModel.ProductModelID = 
                SalesLT.ProductModelProductDescription.ProductModelID 
                INNER JOIN SalesLT.ProductDescription 
                ON SalesLT.ProductModelProductDescription.ProductDescriptionID = 
                SalesLT.ProductDescription.ProductDescriptionID 
                WHERE (SalesLT.ProductModelProductDescription.Culture = @culture) 
                AND (SalesLT.Product.Name = @productname)">
            <SelectParameters>
                <asp:RouteParameter DefaultValue="en" Name="culture" RouteKey="culture" />
                <asp:RouteParameter Name="productname" RouteKey="productname" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" 
            DataSourceID="SqlDataSource1">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

The following example shows a page that is named ProductLinks.aspx, which contains hyperlinks that link to the Product.aspx page by using route URLs. These hyperlinks use RouteUrl expressions to create route URLs. The first link does not include a culture route parameter. Therefore, the default value of "en" that is defined in the RouteParameter object for @culture query parameter will be used in the query. The second link provides a culture value of "fr", which causes the description to be displayed in French. For more information about how to use RouteUrl expressions, see How to: Construct URLs from Routes.

None
<%@ Page %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html >
<head runat="server">
    <title>Product Links Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            Product Links Page
        </h1>
        <asp:HyperLink ID="HyperLink1" runat="server" 
            NavigateUrl="<%$RouteUrl:routename=productroute,productname=LL Bottom Bracket%>">
            Product page for LL Bottom Bracket</asp:HyperLink>
        <br />
        <asp:HyperLink ID="HyperLink8" runat="server" 
            NavigateUrl="<%$RouteUrl:routename=productroute,productname=LL Bottom Bracket,culture=fr%>">
            Product page for LL Bottom Bracket (French)</asp:HyperLink>
    </div>
    </form>
</body>
</html>

When you click the first hyperlink, you see the Product.aspx page with the following values in the GridView control:

ProductID

Name

Description

994

LL Bottom Bracket

Chromoly steel.

When you click the second hyperlink, you see the following values in the GridView control:

ProductID

Name

Description

994

LL Bottom Bracket

Acier chromé.

To run this example, add the two .aspx pages and the code in the Global.asax file to an ASP.NET Web site or Web application that defines a connection string named AdventureWorksLTConnectionString for the AdventureWorksLT database. For information about how to set up a connection to the AdventureWorksLT database, see How to: Set Up an AdventureWorksLT Sample Database for ASP.NET Development.

For more information about ASP.NET routing, see ASP.NET Routing.

.NET Framework

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Bibliothèque de classes .NET Framework
RouteParameter, classe

Lie la valeur d'un segment d'URL à un objet paramètre.

System..::.Object
  System.Web.UI.WebControls..::.Parameter
    System.Web.UI.WebControls..::.RouteParameter

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public Class RouteParameter _
    Inherits Parameter
C#
public class RouteParameter : Parameter
VisualC++
public ref class RouteParameter : public Parameter
F#
type RouteParameter =  
    class
        inherit Parameter
    end

Le type RouteParameter expose les membres suivants.

  NomDescription
Méthode publiqueRouteParameter()()()Initialise une nouvelle instance de la classe RouteParameter.
Méthode protégéeRouteParameter(RouteParameter)Initialise une nouvelle instance de la classe RouteParameter à l'aide des valeurs de l'instance spécifiée.
Méthode publiqueRouteParameter(String, String)Initialise une nouvelle instance de la classe RouteParameter en utilisant le nom spécifié pour le paramètre, et la clé spécifiée pour les données d'itinéraire.
Méthode publiqueRouteParameter(String, DbType, String)Initialise une nouvelle instance de la classe RouteParameter en utilisant le nom et le type de base de données spécifiés pour le paramètre, et la clé spécifiée pour les données d'itinéraire.
Méthode publiqueRouteParameter(String, TypeCode, String)Initialise une nouvelle instance de la classe RouteParameter en utilisant le nom et le type spécifiés pour le paramètre, et la clé spécifiée pour les données d'itinéraire.
Début
  NomDescription
Propriété publiqueConvertEmptyStringToNullObtient ou définit une valeur indiquant si la valeur à laquelle l'objet Parameter est lié doit être convertie en nullNothingnullptrune référence null (Nothing en Visual Basic) si elle est String..::.Empty. (Hérité de Parameter.)
Propriété publiqueDbTypeObtient ou définit le type de base de données du paramètre. (Hérité de Parameter.)
Propriété publiqueDefaultValueSpécifie une valeur par défaut pour le paramètre, à condition que la valeur à laquelle le paramètre est lié à ne soit pas initialisée lorsque la méthode Evaluate est appelée. (Hérité de Parameter.)
Propriété publiqueDirectionIndique si l'objet Parameter est utilisé pour lier une valeur à un contrôle ou si le contrôle peut être utilisé pour modifier la valeur. (Hérité de Parameter.)
Propriété protégéeIsTrackingViewStateObtient une valeur indiquant si l'objet Parameter enregistre les modifications apportées à son état d'affichage. (Hérité de Parameter.)
Propriété publiqueNameObtient ou définit le nom du paramètre. (Hérité de Parameter.)
Propriété publiqueRouteKeyObtient ou définit le nom du segment d'itinéraire à partir duquel la valeur pour le paramètre d'itinéraire doit être extraite.
Propriété publiqueSizeObtient ou définit la taille du paramètre. (Hérité de Parameter.)
Propriété publiqueTypeObtient ou définit le type du paramètre. (Hérité de Parameter.)
Propriété protégéeViewStateObtient un dictionnaire d'informations d'état qui vous permet d'enregistrer et de restaurer l'état d'affichage d'un objet Parameter entre plusieurs demandes de la même page. (Hérité de Parameter.)
Début
  NomDescription
Méthode protégéeCloneRetourne un doublon de l'instance RouteParameter actuelle. (Substitue Parameter..::.Clone()()().)
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeEvaluateÉvalue l'URL de requête et retourne la valeur du paramètre. (Substitue Parameter..::.Evaluate(HttpContext, Control).)
Méthode protégéeFinalizeAutorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode publiqueGetDatabaseTypeObtient la valeur DbType qui est équivalente au type CLR de l'instance Parameter actuelle. (Hérité de Parameter.)
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetTypeObtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode protégéeLoadViewStateRestaure l'état d'affichage enregistré précédemment pour la vue de source de données. (Hérité de Parameter.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode protégéeOnParameterChangedAppelle la méthode OnParametersChanged de la collection ParameterCollection qui contient l'objet Parameter. (Hérité de Parameter.)
Méthode protégéeSaveViewStateEnregistre les modifications apportées à l'état d'affichage de l'objet Parameter depuis la publication de la page sur le serveur. (Hérité de Parameter.)
Méthode protégéeSetDirtyMarque l'objet Parameter afin que son état soit enregistré dans l'état d'affichage. (Hérité de Parameter.)
Méthode publiqueToStringConvertit la valeur de cette instance en sa représentation sous forme de chaîne équivalente. (Hérité de Parameter.)
Méthode protégéeTrackViewStateAinsi, l'objet Parameter effectue le suivi des modifications de son état d'affichage afin qu'elles puissent être stockées dans l'objet ViewState du contrôle et être persistantes entre les demandes de la même page. (Hérité de Parameter.)
Début
  NomDescription
Implémentation d'interface expliciteMéthode privéeICloneable..::.CloneRetourne un doublon de l'instance de Parameter actuelle. (Hérité de Parameter.)
Implémentation d'interface explicitePropriété privéeIStateManager..::.IsTrackingViewStateInfrastructure. Obtient une valeur indiquant si l'objet Parameter enregistre les modifications apportées à son état d'affichage. (Hérité de Parameter.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.LoadViewStateInfrastructure. Restaure l'état d'affichage enregistré précédemment pour la vue de source de données. (Hérité de Parameter.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.SaveViewStateInfrastructure. Enregistre les modifications apportées à l'état d'affichage de l'objet Parameter depuis la publication de la page sur le serveur. (Hérité de Parameter.)
Implémentation d'interface expliciteMéthode privéeIStateManager..::.TrackViewStateInfrastructure. Ainsi, l'objet Parameter effectue le suivi des modifications de son état d'affichage afin qu'elles puissent être stockées dans l'objet ViewState du contrôle et être persistantes entre les demandes de la même page. (Hérité de Parameter.)
Début

Si vous implémentez le routage ASP.NET dans un site Web, vous pouvez utiliser l'objet RouteParameter pour lier la valeur d'un segment de l'URL demandée à une requête de base de données ou une commande. Vous pouvez déclarer des objets RouteParameter dans le balisage pour les contrôles de source de données ou le contrôle QueryExtender.

Un projet de site Web Visual Studio contenant du code source est disponible pour accompagner cette rubrique : Download.

Les exemples de cette section indiquent comment utiliser des objets RouteParameter dans le balisage pour passer des valeurs de paramètre d'URL à une requête spécifiée pour un contrôle de source de données.

L'exemple suivant affiche le code dans la page Global.asax qui définit un itinéraire nommé ProductRoute. L'itinéraire définit un paramètre URL nommé productname. L'itinéraire définit également un paramètre fourre-tout facultatif nommé culture, qui peut être utilisé pour spécifier la langue dans laquelle la description du produit est affichée. La page Product.aspx gère les demandes pour cet itinéraire.

L'exemple suivant illustre la page Product.aspx. La page contient un contrôle SqlDataSource contenant une requête à deux paramètres, un pour le nom du produit et un pour la langue de la description du produit. Les objets RouteParameter sont utilisés pour fournir les valeurs pour les paramètres de requête. La valeur du paramètre de l'URL de routage productname est passée au @productname du paramètre de culture. La valeur du paramètre de l'URL de routage culture est passée au @culture du paramètre de culture. Si une URL de routage n'inclut pas le paramètre URL culture, une valeur par défaut de « en » est utilisée.

None
<%@ Page %>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html >
<head runat="server">
    <title>Product Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Product Page</h1>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorksLTConnectionString %>" 
            SelectCommand="SELECT SalesLT.Product.ProductID, 
                SalesLT.Product.Name, 
                SalesLT.ProductDescription.Description 
                FROM SalesLT.Product 
                INNER JOIN SalesLT.ProductModel 
                ON SalesLT.Product.ProductModelID = 
                SalesLT.ProductModel.ProductModelID 
                INNER JOIN SalesLT.ProductModelProductDescription 
                ON SalesLT.ProductModel.ProductModelID = 
                SalesLT.ProductModelProductDescription.ProductModelID 
                INNER JOIN SalesLT.ProductDescription 
                ON SalesLT.ProductModelProductDescription.ProductDescriptionID = 
                SalesLT.ProductDescription.ProductDescriptionID 
                WHERE (SalesLT.ProductModelProductDescription.Culture = @culture) 
                AND (SalesLT.Product.Name = @productname)">
            <SelectParameters>
                <asp:RouteParameter DefaultValue="en" Name="culture" RouteKey="culture" />
                <asp:RouteParameter Name="productname" RouteKey="productname" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" 
            DataSourceID="SqlDataSource1">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

L'exemple suivant affiche une page nommée ProductLinks.aspx, qui contient des liens hypertexte vers la page Product.aspx utilisant des URL de routage. Ces liens hypertexte utilisent des expressions RouteUrl pour créer des URL d'itinéraire. Le premier lien n'inclut pas de paramètre d'itinéraire culture. Par conséquent, la valeur par défaut de « en » définie dans l'objet RouteParameter pour le paramètre de requête @culture sera utilisée dans la requête. Le deuxième lien fournit une valeur culture « fr », ce qui affiche la description en français. Pour plus d'informations sur l'utilisation des expressions RouteUrl, consultez Comment : construire des URL à partir d'itinéraires.

None
<%@ Page %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html >
<head runat="server">
    <title>Product Links Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            Product Links Page
        </h1>
        <asp:HyperLink ID="HyperLink1" runat="server" 
            NavigateUrl="<%$RouteUrl:routename=productroute,productname=LL Bottom Bracket%>">
            Product page for LL Bottom Bracket</asp:HyperLink>
        <br />
        <asp:HyperLink ID="HyperLink8" runat="server" 
            NavigateUrl="<%$RouteUrl:routename=productroute,productname=LL Bottom Bracket,culture=fr%>">
            Product page for LL Bottom Bracket (French)</asp:HyperLink>
    </div>
    </form>
</body>
</html>

Lorsque vous cliquez sur le premier lien hypertexte, la page Product.aspx s'affiche avec le contrôle GridView comportant les valeurs suivantes :

ProductID

Nom

Description

994

LL Bottom Bracket

Chromoly steel.

Lorsque vous cliquez sur le deuxième lien hypertexte, les valeurs suivantes s'affichent dans le contrôle GridView :

ProductID

Nom

Description

994

LL Bottom Bracket

Acier chromé.

Pour exécuter cet exemple, ajoutez les deux pages .aspx et le code du fichier Global.asax à un site Web ASP.NET ou à application Web qui définit une chaîne de connexion nommée AdventureWorksLTConnectionString pour la base de données AdventureWorksLT. Pour plus d'informations sur la configuration d'une connexion à la base de données AdventureWorksLT, consultez Comment : configurer un exemple de base de données AdventureWorksLT pour le développement ASP.NET.

Pour plus d'informations sur le routage d'ASP.NET, consultez Routage ASP.NET.

.NET Framework

Pris en charge dans : 4

Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2

Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker