次の方法で共有


Page.GetPostBackEventReference メソッド

クライアント側のスクリプト関数への参照を取得します。この関数が呼び出されると、サーバーがページにポスト バックします。

オーバーロードの一覧

クライアント側のスクリプト関数への参照を取得します。この関数が呼び出されると、サーバーがページにポスト バックします。

[Visual Basic] Overloads Public Function GetPostBackEventReference(Control) As String

[C#] public string GetPostBackEventReference(Control);

[C++] public: String* GetPostBackEventReference(Control*);

[JScript] public function GetPostBackEventReference(Control) : String;

クライアント側のスクリプト関数への参照を取得します。この関数が呼び出されると、サーバーがページにポスト バックします。このメソッドも、サーバー上でポストバック処理を実行するサーバー コントロールにパラメータを渡します。

[Visual Basic] Overloads Public Function GetPostBackEventReference(Control, String) As String

[C#] public string GetPostBackEventReference(Control, string);

[C++] public: String* GetPostBackEventReference(Control*, String*);

[JScript] public function GetPostBackEventReference(Control, String) : String;

使用例

[Visual Basic, C#, C++] メモ   ここでは、GetPostBackEventReference のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Public Class MyControl
   Inherits Control
   Implements IPostBackEventHandler

   ' Create an integer property that is displayed when
   ' the page that contains this control is requested
   ' and save it to the control's ViewState property.      
   Public Property Number() As Integer
      Get
         If Not (ViewState("Number") Is Nothing) Then
            Return CInt(ViewState("Number"))
         End If
         Return 50
      End Get
      
      Set
         ViewState("Number") = value
      End Set
   End Property      
   
   ' Implement the RaisePostBackEvent method from the
   ' IPostBackEventHandler interface. If inc is passed
   ' to this method, it increases the Number property by one.
   ' If dec is passed to this method, it decreases the
   ' Number property by one.
   Sub RaisePostBackEvent(eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent

      If eventArgument = "inc" Then
         Number = Number + 1
      End If 
      If eventArgument = "dec" Then
         Number = Number - 1
      End If
   End Sub 'RaisePostBackEvent
   
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ 
   Protected Overrides Sub Render(writer As HtmlTextWriter)
      ' Converts the Number property to a string and
  ' writes it to the containing page.
      writer.Write(("The Number is " + Number.ToString() + " ("))
      
  ' Uses the GetPostBackEventReference method to pass
  ' inc to the RaisePostBackEvent method when the link
  ' this code creates is clicked.
      writer.Write(("<a href=""javascript:" + Page.GetPostBackEventReference(Me, "inc") + """>Increase Number</a>"))
      
      writer.Write(" or ")

  ' Uses the GetPostBackEventReference method to pass
  ' dec to the RaisePostBackEvent method when the link
  ' this code creates is clicked.         
      writer.Write(("<a href=""javascript:" + Page.GetPostBackEventReference(Me, "dec") + """>Decrease Number</a>"))
   End Sub 'Render
End Class 'MyControl

[C#] 
public class MyControl : Control, IPostBackEventHandler
{
   
   // Create an integer property that is displayed when
   // the page that contains this control is requested
   // and save it to the control's ViewState property.
   public int Number
   {
     get
     {
       if ( ViewState["Number"] !=null )
          return (int) ViewState["Number"];
       return 50;
     }

     set
     {
       ViewState["Number"] = value;
     }        
   }

   // Implement the RaisePostBackEvent method from the
   // IPostBackEventHandler interface. If 'inc' is passed
   // to this method, it increases the Number property by one.
   // If 'dec' is passed to this method, it decreases the
   // Number property by one.
   public void RaisePostBackEvent(string eventArgument)
   {
     if ( eventArgument == "inc" )
     Number = Number + 1;

     if ( eventArgument == "dec" )
     Number = Number - 1;
   }

   
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
   protected override void Render(HtmlTextWriter writer)
   {
     // Converts the Number property to a string and
 // writes it to the containing page.
     writer.Write("The Number is " + Number.ToString() + " (" );

 // Uses the GetPostBackEventReference method to pass
 // 'inc' to the RaisePostBackEvent method when the link
 // this code creates is clicked.
     writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"inc") + "\">Increase Number</a>"); 

     writer.Write(" or ");

 // Uses the GetPostBackEventReference method to pass
 // 'dec' to the RaisePostBackEvent method when the link
 // this code creates is clicked.
     writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"dec") + "\">Decrease Number</a>");
   }
}

[C++] 
public __gc class MyControl : public Control, public IPostBackEventHandler
{
   // Create an integer property that is displayed when
   // the page that contains this control is requested
   // and save it to the control's ViewState property.
public:
   __property int get_Number() 
   {
      if (ViewState->get_Item(S"Number") !=0)
         return * dynamic_cast<__box int*>(ViewState->get_Item(S"Number"));
      return 50;
   }

   __property void set_Number(int value) 
   {
      ViewState->Item[S"Number"] = __box(value);
   }

   // Implement the RaisePostBackEvent method from the
   // IPostBackEventHandler* interface. If 'inc' is passed
   // to this method, it increases the Number property by one.
   // If 'dec' is passed to this method, it decreases the
   // Number property by one.
   void RaisePostBackEvent(String* eventArgument)
   {
      if (String::Compare(eventArgument, S"inc") == 0)
         Number = Number + 1;

      if (String::Compare(eventArgument, S"dec") == 0)
         Number = Number - 1;
   }

protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
   void Render(HtmlTextWriter* writer)
   {
      // Converts the Number property to a String* and
      // writes it to the containing page.
      writer->Write(S"The Number is {0} (", __box(Number));

      // Uses the GetPostBackEventReference method to pass
      // 'inc' to the RaisePostBackEvent method when the link
      // this code creates is clicked.
      writer->Write(S"<a href=\"javascript: {0} \">Increase Number</a>", 
         Page->GetPostBackEventReference(this,S"inc"));

      writer->Write(S" or ");

      // Uses the GetPostBackEventReference method to pass
      // 'dec' to the RaisePostBackEvent method when the link
      // this code creates is clicked.
      writer->Write(S"<a href=\"javascript:S {0} \">Decrease Number</a>", 
         Page->GetPostBackEventReference(this, S"decS"));
   }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Page クラス | Page メンバ | System.Web.UI 名前空間