PostBackOptions Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Spécifie la façon dont JavaScript côté client est généré pour lancer un événement de publication.
public ref class PostBackOptions sealed
public sealed class PostBackOptions
type PostBackOptions = class
Public NotInheritable Class PostBackOptions
- Héritage
-
PostBackOptions
Exemples
L’exemple de code suivant utilise l’événement OnClick d’un Button contrôle pour générer un script côté client pour un HyperLink contrôle qui permettra au HyperLink contrôle de provoquer un événement de publication. Étant donné que la ActionUrl propriété de l’objet myPostBackOptions est définie sur « Page2.aspx », la publication publiera la page Web Forms sur une autre page nommée « Page2.aspx », qui n’est pas fournie ici. Pour utiliser cet exemple, vous devez ajouter une autre page web nommée « Page2.aspx » à votre projet ou répertoire.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class postbackoptionscs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
Label1.Text = "A postback event has occurred.";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// Create a new PostBackOptions object and set its properties.
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.ActionUrl = "Page2.aspx";
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.RequiresJavaScriptProtocol = true;
myPostBackOptions.PerformValidation = true;
// Add the client-side script to the HyperLink1 control.
HyperLink1.NavigateUrl = Page.ClientScript.GetPostBackEventReference(myPostBackOptions);
Label1.Text = "Click this hyperlink to initiate a postback event.";
}
}
Partial Class postbackoptionsvb
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
' Create a new PostBackOptions object and set its properties.
Dim myPostBackOptions As PostBackOptions = New PostBackOptions(Me)
myPostBackOptions.ActionUrl = "Page2.aspx"
myPostBackOptions.AutoPostBack = False
myPostBackOptions.RequiresJavaScriptProtocol = True
myPostBackOptions.PerformValidation = True
' Add the client-side script to the HyperLink1 control.
HyperLink1.NavigateUrl = Page.ClientScript.GetPostBackEventReference(myPostBackOptions)
Label1.Text = "Click this hyperlink to initiate a postback event."
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Label1.Text = "A postback event has occurred."
End If
End Sub
End Class
L’exemple de code suivant est une page web qui peut être utilisée pour exécuter le fichier code-behind précédent.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="postbackoptions.aspx.cs" Inherits="postbackoptionscs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PostBackOptions Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>PostBackOptions Example Page</h3>
Click this button to create client-side script for the
Postback hyperlink that causes a postback event to occur.
<br />
<asp:Button id="Button1"
runat="server"
text="Create Script"
onclick="Button1_Click" />
<br /><br />
<asp:Label id="Label1"
runat="server"
text="">
</asp:Label>
<br />
<asp:HyperLink id="HyperLink1"
runat="server"
text="Postback">
</asp:HyperLink>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="postbackoptions.aspx.vb" Inherits="postbackoptionsvb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PostBackOptions Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>PostBackOptions Example Page</h3>
Click this button to create client-side script for the
Postback hyperlink that causes a postback event to occur.
<br />
<asp:Button id="Button1"
runat="server"
text="Create Script"
onclick="Button1_Click" />
<br /><br />
<asp:Label id="Label1"
runat="server"
text=""></asp:Label>
<br />
<asp:HyperLink id="HyperLink1"
runat="server"
text="Postback"></asp:HyperLink>
<br />
</form>
</body>
</html>
Remarques
La PostBackOptions classe permet aux contrôles d’émettre un script côté client qui lance un événement de publication. La PostBackOptions classe fournit également une référence au contrôle qui a lancé l’événement de publication par le biais de la TargetControl propriété. L’événement de publication est créé en fonction des options spécifiées dans l’objet PostBackOptions transmis à la ClientScriptManager.GetPostBackEventReference méthode.
Normalement, une publication sur le serveur est lancée par des éléments tels qu’un bouton Envoyer ou un bouton Image. Toutefois, en émettant javaScript côté client, différents contrôles peuvent lancer un événement de publication.
Constructeurs
| Nom | Description |
|---|---|
| PostBackOptions(Control, String, String, Boolean, Boolean, Boolean, Boolean, Boolean, String) |
Initialise une nouvelle instance de la PostBackOptions classe avec les valeurs spécifiées pour les propriétés de l’instance. |
| PostBackOptions(Control, String) |
Initialise une nouvelle instance de la PostBackOptions classe avec les données de contrôle cible et d’argument spécifiées. |
| PostBackOptions(Control) |
Initialise une nouvelle instance de la PostBackOptions classe avec les données de contrôle cible spécifiées. |
Propriétés
| Nom | Description |
|---|---|
| ActionUrl |
Obtient ou définit l’URL cible pour la publication d’une page Web Forms. |
| Argument |
Obtient ou définit un argument facultatif transféré dans l’événement de publication. |
| AutoPostBack |
Obtient ou définit une valeur qui indique si le formulaire revient automatiquement au serveur en réponse à une action utilisateur. |
| ClientSubmit |
Obtient ou définit une valeur indiquant si l’événement de publication doit se produire à partir du script côté client. |
| PerformValidation |
Obtient ou définit une valeur indiquant si la validation côté client est requise avant que l’événement de publication ne se produise. |
| RequiresJavaScriptProtocol |
Obtient ou définit une valeur indiquant si le |
| TargetControl |
Obtient la cible de contrôle qui reçoit l’événement de publication. |
| TrackFocus |
Obtient ou définit une valeur indiquant si l’événement de publication doit renvoyer la page à la position de défilement actuelle et retourner le focus au contrôle actuel. |
| ValidationGroup |
Obtient ou définit le groupe de contrôles pour lesquels l’objet provoque la PostBackOptions validation lorsqu’il revient au serveur. |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |