Partager via


ClientScriptManager.GetPostBackEventReference Méthode

Définition

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur.

Surcharges

Nom Description
GetPostBackEventReference(Control, String, Boolean)

Retourne une chaîne à utiliser dans un événement client pour provoquer la publication sur le serveur. La chaîne de référence est définie par le contrôle spécifié qui gère la publication et un argument de chaîne d’informations d’événement supplémentaires. Si vous le souhaitez, inscrit la référence d’événement pour la validation.

GetPostBackEventReference(PostBackOptions, Boolean)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par l’objet spécifié PostBackOptions . Si vous le souhaitez, inscrit la référence d’événement pour la validation.

GetPostBackEventReference(PostBackOptions)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par l’instance spécifiée PostBackOptions .

GetPostBackEventReference(Control, String)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par le contrôle spécifié qui gère la publication et un argument de chaîne d’informations d’événement supplémentaires.

GetPostBackEventReference(Control, String, Boolean)

Retourne une chaîne à utiliser dans un événement client pour provoquer la publication sur le serveur. La chaîne de référence est définie par le contrôle spécifié qui gère la publication et un argument de chaîne d’informations d’événement supplémentaires. Si vous le souhaitez, inscrit la référence d’événement pour la validation.

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control, System::String ^ argument, bool registerForEventValidation);
public string GetPostBackEventReference(System.Web.UI.Control control, string argument, bool registerForEventValidation);
member this.GetPostBackEventReference : System.Web.UI.Control * string * bool -> string
Public Function GetPostBackEventReference (control As Control, argument As String, registerForEventValidation As Boolean) As String

Paramètres

control
Control

Serveur Control qui traite la publication sur le serveur.

argument
String

Chaîne d’arguments facultatifs à passer à control.

registerForEventValidation
Boolean

true pour inscrire la référence d’événement pour la validation ; sinon, false.

Retours

Chaîne qui, lorsqu’elle est traitée comme un script sur le client, lance la publication.

Exceptions

La valeur spécifiée Control est null.

Remarques

Pour implémenter l’interface IPostBackEventHandler pour un Page, utilisez la @ Implements directive.

La GetPostBackEventReference méthode peut être utilisée avec le Button contrôle lorsque la UseSubmitBehavior propriété est false. Dans ce scénario, la GetPostBackEventReference méthode retourne l’événement de publication du client pour le Button contrôle.

Si registerForEventValidation elle est vraie, la GetPostBackEventReference(PostBackOptions, Boolean) méthode appelle la RegisterForEventValidation(String, String) méthode pour inscrire la référence d’événement pour la validation avec un ID de contrôle unique qui représente le contrôle client qui génère l’événement.

Voir aussi

S’applique à

GetPostBackEventReference(PostBackOptions, Boolean)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par l’objet spécifié PostBackOptions . Si vous le souhaitez, inscrit la référence d’événement pour la validation.

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::PostBackOptions ^ options, bool registerForEventValidation);
public string GetPostBackEventReference(System.Web.UI.PostBackOptions options, bool registerForEventValidation);
member this.GetPostBackEventReference : System.Web.UI.PostBackOptions * bool -> string
Public Function GetPostBackEventReference (options As PostBackOptions, registerForEventValidation As Boolean) As String

Paramètres

options
PostBackOptions

Qui PostBackOptions définit le postback.

registerForEventValidation
Boolean

true pour inscrire la référence d’événement pour la validation ; sinon, false.

Retours

Chaîne qui, lorsqu’elle est traitée comme un script sur le client, lance la publication du client.

Exceptions

Remarques

Pour implémenter l’interface IPostBackEventHandler d’un Page objet, utilisez la @ Implements directive.

La GetPostBackEventReference méthode peut être utilisée avec le Button contrôle lorsque la UseSubmitBehavior propriété est false. Dans ce scénario, la GetPostBackEventReference méthode retourne l’événement de publication du client pour le Button contrôle.

Si registerForEventValidation c’est truele cas, la GetPostBackEventReference(PostBackOptions, Boolean) méthode appelle la RegisterForEventValidation(String, String) méthode pour inscrire la référence d’événement pour la validation avec un ID de contrôle unique qui représente le contrôle client qui génère l’événement.

Voir aussi

S’applique à

GetPostBackEventReference(PostBackOptions)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par l’instance spécifiée PostBackOptions .

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::PostBackOptions ^ options);
public string GetPostBackEventReference(System.Web.UI.PostBackOptions options);
member this.GetPostBackEventReference : System.Web.UI.PostBackOptions -> string
Public Function GetPostBackEventReference (options As PostBackOptions) As String

Paramètres

options
PostBackOptions

Qui PostBackOptions définit le postback.

Retours

Chaîne qui, lorsqu’elle est traitée comme un script sur le client, lance la publication du client.

Exceptions

Le PostBackOptions paramètre est null

Remarques

Pour implémenter l’interface IPostBackEventHandler pour un Page, utilisez la @ Implements directive.

La GetPostBackEventReference méthode peut être utilisée avec le Button contrôle lorsque la UseSubmitBehavior propriété est false. Dans ce scénario, la GetPostBackEventReference méthode retourne l’événement de publication du client pour le Button contrôle.

Voir aussi

S’applique à

GetPostBackEventReference(Control, String)

Retourne une chaîne qui peut être utilisée dans un événement client pour provoquer une publication sur le serveur. La chaîne de référence est définie par le contrôle spécifié qui gère la publication et un argument de chaîne d’informations d’événement supplémentaires.

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control, System::String ^ argument);
public string GetPostBackEventReference(System.Web.UI.Control control, string argument);
member this.GetPostBackEventReference : System.Web.UI.Control * string -> string
Public Function GetPostBackEventReference (control As Control, argument As String) As String

Paramètres

control
Control

Serveur Control qui traite la publication sur le serveur.

argument
String

Chaîne d’arguments facultatifs à passer au contrôle qui traite la publication.

Retours

Chaîne qui, lorsqu’elle est traitée comme un script sur le client, lance la publication.

Exceptions

La valeur spécifiée Control est null.

Exemples

L’exemple de code suivant illustre l’utilisation de la GetPostBackEventReference méthode. Le contrôle personnalisé, implémente MyControll’interface IPostBackEventHandler . Lorsque le bouton de la page est cliqué, la RaisePostBackEvent méthode du contrôle personnalisé est appelée.

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

  public class MyControl : Label, IPostBackEventHandler
  {

    // Use the constructor to defined default label text.
    public MyControl()
    {
      base.Text = "No postback raised.";
    }
    
    // Implement the RaisePostBackEvent method from the
    // IPostBackEventHandler interface. 
    public void RaisePostBackEvent(string eventArgument)
    {
      base.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
                  "Postback caused by " + eventArgument.ToString() + ".";
      
    }
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Create an instance of the custom label control and 
    // add it to the page.
    MyControl mycontrol = new MyControl();
    mycontrol.ID = "mycontrol1";
    PlaceHolder1.Controls.Add(mycontrol);
    PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
    
    // Create a button element with its onClick attribute defined
    // to create a postback event reference to the custom label control.
    HtmlInputButton b = new HtmlInputButton();
    b.ID = "mybutton1";
    b.Value = "Click";
    b.Attributes.Add("onclick", cs.GetPostBackEventReference(mycontrol, b.ID.ToString()));
    PlaceHolder1.Controls.Add(b);
    PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
    
    // Create a link element with its href attribute defined
    // to create a postback event reference to the custom label control.
    HtmlAnchor a = new HtmlAnchor();
    a.ID = "myanchor1";
    a.InnerText = "link";
    a.HRef = cs.GetPostBackClientHyperlink(mycontrol, a.ID.ToString());
    PlaceHolder1.Controls.Add(a);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:PlaceHolder id="PlaceHolder1" 
                       runat="server">
      </asp:PlaceHolder>
    </div>
    </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">
  
  Public Class MyControl
    Inherits Label
    Implements IPostBackEventHandler
     
    Public Sub New()
      
      MyBase.Text = "No postback raised."
    
    End Sub
    
    Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
      
      MyBase.Text = "Postback handled by " & Me.ID.ToString() & ". <br/>" & _
                "Postback caused by " + eventArgument.ToString() & "."

    End Sub
    
  End Class
   

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript

    ' Create an instance of the custom label control and 
    ' add it to the page.
    Dim mycontrol As New MyControl()
    MyControl.ID = "mycontrol1"
    PlaceHolder1.Controls.Add(MyControl)
    PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
    
    ' Create a button element with its onClick attribute defined
    ' to create a postback event reference to the custom label control.
    Dim b As New HtmlInputButton()
    b.ID = "mybutton1"
    b.Value = "Click"
    b.Attributes.Add("onclick", cs.GetPostBackEventReference(MyControl, b.ID.ToString()))
    PlaceHolder1.Controls.Add(b)
    PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
    
    ' Create a link element with its href attribute defined
    ' to create a postback event reference to the custom label control.
    Dim a As New HtmlAnchor()
    a.ID = "myanchor1"
    a.InnerText = "link"
    a.HRef = cs.GetPostBackClientHyperlink(MyControl, a.ID.ToString())
    PlaceHolder1.Controls.Add(a)
    
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:PlaceHolder id="PlaceHolder1" 
                       runat="server">
      </asp:PlaceHolder>
    </div>
    </form>
</body>
</html>

L’exemple de code suivant présente les mêmes fonctionnalités que celles précédentes, sauf que, au lieu d’un contrôle personnalisé, la Page classe implémente l’interface IPostBackEventHandler .

<%@ Page Language="C#"  %>
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>

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

<script runat="server">
  
  public void RaisePostBackEvent(string eventArgument)
  {
    Label1.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
                  "Postback caused by " + eventArgument.ToString() + "."; ;
  }
  
  protected void Page_Load(object sender, EventArgs e)
  {
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;
    
    // Create a button element with its onClick attribute defined
    // to create a postback event reference to the custom label control.
    HtmlInputButton b = new HtmlInputButton();
    b.ID = "mybutton1";
    b.Value = "Click";
    b.Attributes.Add("onclick", cs.GetPostBackEventReference(this, b.ID.ToString()));
    PlaceHolder1.Controls.Add(b);
    PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
    
    // Create a link element with its href attribute defined
    // to create a postback event reference to the custom label control.
    HtmlAnchor a = new HtmlAnchor();
    a.ID = "myanchor1";
    a.InnerText = "link";
    a.HRef = cs.GetPostBackClientHyperlink(this, a.ID.ToString());
    PlaceHolder1.Controls.Add(a);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label id="Label1"
                 runat="server" />
      <br />
      <asp:PlaceHolder id="PlaceHolder1" 
                       runat="server">
      </asp:PlaceHolder>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>

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

<script runat="server">
 
  Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
    Implements IPostBackEventHandler.RaisePostBackEvent
    
    Label1.Text = "Postback handled by " & Me.ID.ToString() & ". <br/>" & _
           "Postback caused by " + eventArgument.ToString() & "."
  
  End Sub
  

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript
    
    ' Create a button element with its onClick attribute defined
    ' to create a postback event reference to the custom label control.
    Dim b As New HtmlInputButton()
    b.ID = "mybutton1"
    b.Value = "Click"
    b.Attributes.Add("onclick", cs.GetPostBackEventReference(Me, b.ID.ToString()))
    PlaceHolder1.Controls.Add(b)
    PlaceHolder1.Controls.Add(New LiteralControl("<br/>"))
    
    ' Create a link element with its href attribute defined
    ' to create a postback event reference to the custom label control.
    Dim a As New HtmlAnchor()
    a.ID = "myanchor1"
    a.InnerText = "link"
    a.HRef = cs.GetPostBackClientHyperlink(Me, a.ID.ToString())
    PlaceHolder1.Controls.Add(a)
    
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label id="Label1"
                 runat="server" />
      <br />
      <asp:PlaceHolder id="PlaceHolder1" 
                       runat="server">
      </asp:PlaceHolder>
    </div>
    </form>
</body>
</html>

Remarques

Pour implémenter l’interface IPostBackEventHandler pour un Page, utilisez la @ Implements directive.

La GetPostBackEventReference méthode peut être utilisée avec le Button contrôle lorsque la UseSubmitBehavior propriété est false. Dans ce scénario, la GetPostBackEventReference méthode retourne l’événement de publication du client pour le Button contrôle.

Voir aussi

S’applique à