ClientScriptManager.GetPostBackEventReference メソッド

定義

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。

オーバーロード

GetPostBackEventReference(Control, String, Boolean)

クライアント イベントで使用する、サーバーにポストバックするための文字列を返します。 この参照文字列は、ポストバックと追加のイベント情報の文字列引数を処理する、指定したコントロールによって定義されます。 オプションで、検証用にこのイベント参照を登録します。

GetPostBackEventReference(PostBackOptions, Boolean)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、指定した PostBackOptions オブジェクトによって定義されます。 オプションで、検証用にこのイベント参照を登録します。

GetPostBackEventReference(PostBackOptions)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、指定された PostBackOptions インスタンスによって定義されます。

GetPostBackEventReference(Control, String)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、ポストバックと追加のイベント情報の文字列引数を処理する、指定したコントロールによって定義されます。

GetPostBackEventReference(Control, String, Boolean)

クライアント イベントで使用する、サーバーにポストバックするための文字列を返します。 この参照文字列は、ポストバックと追加のイベント情報の文字列引数を処理する、指定したコントロールによって定義されます。 オプションで、検証用にこのイベント参照を登録します。

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

パラメーター

control
Control

サーバー上でポストバックを処理するサーバー Control

argument
String

control に渡すオプション引数の文字列。

registerForEventValidation
Boolean

検証用にイベント参照を登録する場合は true。それ以外の場合は false

戻り値

クライアントでスクリプトとして扱われた場合に、ポストバックを初期化する文字列。

例外

指定された Controlnull です。

注釈

PageインターフェイスをIPostBackEventHandler実装するには、 ディレクティブを@ Implements使用します。

プロパティfalseGetPostBackEventReference の場合は、 メソッドを Button コントロールと共にUseSubmitBehavior使用できます。 このシナリオでは、 メソッドは GetPostBackEventReference コントロールのクライアント ポストバック イベントを Button 返します。

が true の場合 registerForEventValidation 、メソッドは GetPostBackEventReference(PostBackOptions, Boolean) メソッドを RegisterForEventValidation(String, String) 呼び出して、検証用のイベント参照を、イベントを生成しているクライアント コントロールを表す一意のコントロール ID で登録します。

こちらもご覧ください

適用対象

GetPostBackEventReference(PostBackOptions, Boolean)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、指定した PostBackOptions オブジェクトによって定義されます。 オプションで、検証用にこのイベント参照を登録します。

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

パラメーター

options
PostBackOptions

ポストバックを定義する PostBackOptions

registerForEventValidation
Boolean

検証用にイベント参照を登録する場合は true。それ以外の場合は false

戻り値

クライアントでスクリプトとして扱われた場合に、クライアント ポストバックを初期化する文字列。

例外

注釈

オブジェクトの インターフェイスPageIPostBackEventHandler実装するには、 ディレクティブを@ Implements使用します。

プロパティfalseGetPostBackEventReference の場合は、 メソッドを Button コントロールと共にUseSubmitBehavior使用できます。 このシナリオでは、 メソッドは GetPostBackEventReference コントロールのクライアント ポストバック イベントを Button 返します。

が の場合registerForEventValidation、メソッドは GetPostBackEventReference(PostBackOptions, Boolean) メソッドをRegisterForEventValidation(String, String)呼び出して、検証用のイベント参照を、イベントを生成しているクライアント コントロールを表す一意のコントロール ID で登録trueします。

こちらもご覧ください

適用対象

GetPostBackEventReference(PostBackOptions)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、指定された 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

パラメーター

options
PostBackOptions

ポストバックを定義する PostBackOptions

戻り値

クライアントでスクリプトとして扱われた場合に、クライアント ポストバックを初期化する文字列。

例外

PostBackOptions パラメーターが null です。

注釈

PageインターフェイスをIPostBackEventHandler実装するには、 ディレクティブを@ Implements使用します。

プロパティfalseGetPostBackEventReference の場合は、 メソッドを Button コントロールと共にUseSubmitBehavior使用できます。 このシナリオでは、 メソッドは GetPostBackEventReference コントロールのクライアント ポストバック イベントを Button 返します。

こちらもご覧ください

適用対象

GetPostBackEventReference(Control, String)

クライアント イベントで使用できる、サーバーにポストバックするための文字列を返します。 この参照文字列は、ポストバックと追加のイベント情報の文字列引数を処理する、指定したコントロールによって定義されます。

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

パラメーター

control
Control

サーバー上でポストバックを処理するサーバー Control

argument
String

ポストバックを処理するコントロールに渡されるオプション引数の文字列。

戻り値

クライアントでスクリプトとして扱われた場合に、ポストバックを初期化する文字列。

例外

指定された Controlnull です。

次のコード例では、 メソッドの使用方法を GetPostBackEventReference 示します。 カスタム コントロール は、 MyControlインターフェイスを IPostBackEventHandler 実装します。 ページ上のボタンをクリックすると、 RaisePostBackEvent カスタム コントロールのメソッドが呼び出されます。

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

次のコード例は、前のコードと同じ機能を備えていますが、カスタム コントロールの代わりに、 クラスによって Page インターフェイスが実装される点が 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>

注釈

PageインターフェイスをIPostBackEventHandler実装するには、 ディレクティブを@ Implements使用します。

プロパティfalseGetPostBackEventReference の場合は、 メソッドを Button コントロールと共にUseSubmitBehavior使用できます。 このシナリオでは、 メソッドは GetPostBackEventReference コントロールのクライアント ポストバック イベントを Button 返します。

こちらもご覧ください

適用対象