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
SessionParameter, 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
SessionParameter Class

Binds the value of a session variable to a parameter object.

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

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

The SessionParameter type exposes the following members.

  NameDescription
Public methodSessionParameter()()()Initializes a new unnamed instance of the SessionParameter class.
Protected methodSessionParameter(SessionParameter)Initializes a new instance of the SessionParameter class with the values of the instance specified by the original parameter.
Public methodSessionParameter(String, String)Initializes a new named instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.
Public methodSessionParameter(String, DbType, String)Initializes a new instance of the SessionParameter class, by using the specified name and type, and binding the parameter to the specified session state name/value pair. This constructor is for database types.
Public methodSessionParameter(String, TypeCode, String)Initializes a new named and strongly typed instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.
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 propertySessionFieldGets or sets the name of the session variable that the parameter binds to.
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 SessionParameter instance. (Overrides Parameter..::.Clone()()().)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodEvaluateUpdates and returns the value of the SessionParameter object. (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

A SessionParameter object is typically used in order to include the value of an HttpSessionState variable in the Where clause of a database query. The SessionField property identifies the session variable from which the SessionParameter retrieves a value.

NoteNote

Controls that bind data to a parameter by using a SessionParameter object might throw an exception if the specified session variable is not set. To avoid this error (where appropriate), set the DefaultValue property.

The following example shows how to use a SessionParameter object. The example assumes that another page has stored an employee ID value in a session variable named empid. The example page uses the empid session variable in the Where clause of a query and displays the result of the query in a GridView control. Because the DefaultValue property of the SessionParameter object is set to 5, data for the record that has the employeeID value of 5 will still be displayed if no session variable named empid is set before you run the example.

Visual Basic
<%@ Page language="VB"%>
<!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>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show My Orders:</p>

      <asp:SqlDataSource
          id="OdbcDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          ConnectionString="dsn=MyOdbcDsn;"
          SelectCommand="SELECT OrderId, CustomerId, OrderDate 
                         FROM Orders 
                         WHERE EmployeeID = ? 
                         ORDER BY CustomerId ASC;">
          <SelectParameters>
              <asp:SessionParameter
                Name="empid"
                SessionField="empid"
                DefaultValue="5" />
          </SelectParameters>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
          id="GridView1"
          runat="server"
          DataSourceID="OdbcDataSource1" />
      </p>
    </form>
  </body>
</html>
C#
<%@ Page language="C#"%>
<!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>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show My Orders:</p>

      <asp:SqlDataSource
          id="OdbcDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          ConnectionString="dsn=MyOdbcDsn;"
          SelectCommand="SELECT OrderId, CustomerId, OrderDate
                         FROM Orders
                         WHERE EmployeeID = ?
                         ORDER BY CustomerId ASC;">
          <SelectParameters>
              <asp:SessionParameter
                Name="empid"
                SessionField="empid"
                DefaultValue="5" />
          </SelectParameters>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
          id="GridView1"
          runat="server"
          DataSourceID="OdbcDataSource1" />
      </p>
    </form>
  </body>
</html>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, 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
SessionParameter, classe

Lie la valeur d'une variable de session à un objet Parameter.

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

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

Le type SessionParameter expose les membres suivants.

  NomDescription
Méthode publiqueSessionParameter()()()Initialise une nouvelle instance sans nom de la classe SessionParameter.
Méthode protégéeSessionParameter(SessionParameter)Initialise une nouvelle instance de la classe SessionParameter avec les valeurs de l'instance spécifiée par le paramètre original.
Méthode publiqueSessionParameter(String, String)Initialise une nouvelle instance nommée de la classe SessionParameter à l'aide de la chaîne spécifiée pour identifier la paire nom/valeur d'état de session à lier.
Méthode publiqueSessionParameter(String, DbType, String)Initialise une nouvelle instance de la classe SessionParameter à l'aide du nom et du type spécifiés, puis en liant le paramètre à la paire nom/valeur d'état de session spécifiée. Ce constructeur est destiné aux types de base de données.
Méthode publiqueSessionParameter(String, TypeCode, String)Initialise une nouvelle instance nommée et fortement typée de la classe SessionParameter à l'aide de la chaîne spécifiée pour identifier la paire nom/valeur d'état de session à lier.
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é publiqueSessionFieldObtient ou définit le nom de la variable de session liée au paramètre.
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 de SessionParameter 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éeEvaluateMet à jour et retourne la valeur de l'objet SessionParameter. (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

Un objet SessionParameter est généralement utilisé pour inclure la valeur d'une variable HttpSessionState dans la clause Where d'une requête de base de données. La propriété SessionField identifie la variable de session à partir de laquelle le SessionParameter récupère une valeur.

RemarqueRemarque

Les contrôles qui lient des données à un paramètre à l'aide d'un objet SessionParameter sont susceptibles de lever une exception si la variable de session spécifiée n'est pas définie. Pour éviter cette erreur (lorsque c'est nécessaire), définissez la propriété DefaultValue.

L'exemple ci-dessous explique comment utiliser un objet SessionParameter. L'exemple suppose qu'une autre page a stocké une valeur Employee ID dans une variable de session nommée empid. La page d'exemple utilise la variable de session empid dans la clause Where d'une requête et affiche le résultat de la requête dans un contrôle GridView. Étant donné que la propriété DefaultValue de l'objet SessionParameter a la valeur 5, les données de l'enregistrement qui ont la valeur employeeID 5 restent affichées si aucune variable de session nommée empid n'est définie avant l'exécution de l'exemple.

Visual Basic
<%@ Page language="VB"%>
<!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>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show My Orders:</p>

      <asp:SqlDataSource
          id="OdbcDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          ConnectionString="dsn=MyOdbcDsn;"
          SelectCommand="SELECT OrderId, CustomerId, OrderDate 
                         FROM Orders 
                         WHERE EmployeeID = ? 
                         ORDER BY CustomerId ASC;">
          <SelectParameters>
              <asp:SessionParameter
                Name="empid"
                SessionField="empid"
                DefaultValue="5" />
          </SelectParameters>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
          id="GridView1"
          runat="server"
          DataSourceID="OdbcDataSource1" />
      </p>
    </form>
  </body>
</html>
C#
<%@ Page language="C#"%>
<!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>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show My Orders:</p>

      <asp:SqlDataSource
          id="OdbcDataSource1"
          runat="server"
          ProviderName="System.Data.Odbc"
          ConnectionString="dsn=MyOdbcDsn;"
          SelectCommand="SELECT OrderId, CustomerId, OrderDate
                         FROM Orders
                         WHERE EmployeeID = ?
                         ORDER BY CustomerId ASC;">
          <SelectParameters>
              <asp:SessionParameter
                Name="empid"
                SessionField="empid"
                DefaultValue="5" />
          </SelectParameters>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
          id="GridView1"
          runat="server"
          DataSourceID="OdbcDataSource1" />
      </p>
    </form>
  </body>
</html>

.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, 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