Page.GetPostBackEventReference Page.GetPostBackEventReference Page.GetPostBackEventReference Method

定義

傳回字串,該字串可用於用戶端事件中造成回傳給伺服器。Returns a string that can be used in a client event to cause postback to the server. 這個方法已被取代。This method has been deprecated. 請改用 GetPostBackEventReference 類別中的 ClientScriptManager 方法。Use the GetPostBackEventReference method in the ClientScriptManager class instead.

多載

GetPostBackEventReference(Control) GetPostBackEventReference(Control) GetPostBackEventReference(Control)

傳回字串,該字串可用於用戶端事件中造成回傳給伺服器。Returns a string that can be used in a client event to cause postback to the server. 指定的 Control 物件會定義參考字串。The reference string is defined by the specified Control object.

GetPostBackEventReference(Control, String) GetPostBackEventReference(Control, String) GetPostBackEventReference(Control, String)

傳回字串,該字串可用於用戶端事件中造成回傳給伺服器。Returns a string that can be used in a client event to cause postback to the server. 參考字串是由處理回傳的指定控制項和其他事件資訊的字串引數所定義。The reference string is defined by the specified control that handles the postback and a string argument of additional event information.

GetPostBackEventReference(Control) GetPostBackEventReference(Control) GetPostBackEventReference(Control)

警告

此 API 現已淘汰。

傳回字串,該字串可用於用戶端事件中造成回傳給伺服器。Returns a string that can be used in a client event to cause postback to the server. 指定的 Control 物件會定義參考字串。The reference string is defined by the specified Control object.

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control);
[System.Obsolete("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202")]
public string GetPostBackEventReference (System.Web.UI.Control control);
member this.GetPostBackEventReference : System.Web.UI.Control -> string

參數

control
Control Control Control

在伺服器上處理回傳的伺服器控制項。The server control to process the postback on the server.

傳回

視為用戶端上的指令碼時,啟始回傳的字串。A string that, when treated as script on the client, initiates the postback.

範例

   public class MyControl1 : 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.
      public void RaisePostBackEvent(string eventArgument)
      {
        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) + "\">Increase Number</a>");
      }
   }
 Public Class MyControl1
    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.      
    Public Sub RaisePostBackEvent(eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent

       Number = Number + 1
    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) + """>Increase Number</a>"))
    End Sub 'Render
 End Class 'MyControl1

備註

這個方法已被取代。This method has been deprecated. 請改用 GetPostBackEventReference 類別中的 ClientScriptManager 方法。Use the GetPostBackEventReference method in the ClientScriptManager class instead.

另請參閱

GetPostBackEventReference(Control, String) GetPostBackEventReference(Control, String) GetPostBackEventReference(Control, String)

警告

此 API 現已淘汰。

傳回字串,該字串可用於用戶端事件中造成回傳給伺服器。Returns a string that can be used in a client event to cause postback to the server. 參考字串是由處理回傳的指定控制項和其他事件資訊的字串引數所定義。The reference string is defined by the specified control that handles the postback and a string argument of additional event information.

public:
 System::String ^ GetPostBackEventReference(System::Web::UI::Control ^ control, System::String ^ argument);
[System.Obsolete("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202")]
public string GetPostBackEventReference (System.Web.UI.Control control, string argument);
member this.GetPostBackEventReference : System.Web.UI.Control * string -> string

參數

control
Control Control Control

用來處理回傳的伺服器控制項。The server control to process the postback.

argument
String String String

傳遞給伺服器控制項的參數。The parameter passed to the server control.

傳回

視為用戶端上的指令碼時,啟始回傳的字串。A string that, when treated as script on the client, initiates the postback.

範例

   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>");
      }
   }
 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

備註

這個方法已被取代。This method has been deprecated. 請改用 GetPostBackEventReference 類別中的 ClientScriptManager 方法。Use the GetPostBackEventReference method in the ClientScriptManager class instead.

另請參閱

適用於