Share via


Page.GetPostBackEventReference 方法

定义

返回一个可以在客户端事件中使用的字符串,以便回发到服务器。 此方法已被否决。 请改用 GetPostBackEventReference 类中的 ClientScriptManager 方法。

重载

GetPostBackEventReference(Control)
已过时.

返回一个可以在客户端事件中使用的字符串,以便回发到服务器。 由指定的 Control 对象定义的字符串。

GetPostBackEventReference(Control, String)
已过时.

返回一个可以在客户端事件中使用的字符串,以便回发到服务器。 该引用字符串由处理回发的指定控件和一个附加事件信息的字符串参数定义。

GetPostBackEventReference(Control)

注意

The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202

返回一个可以在客户端事件中使用的字符串,以便回发到服务器。 由指定的 Control 对象定义的字符串。

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

参数

control
Control

要在服务器上处理回发的服务器控件。

返回

一个字符串,将其视为客户端脚本时,将启动回发。

属性

示例

   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
   
   <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
End Class

注解

此方法已被否决。 请改用 GetPostBackEventReference 类中的 ClientScriptManager 方法。

另请参阅

适用于

GetPostBackEventReference(Control, String)

注意

The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202

返回一个可以在客户端事件中使用的字符串,以便回发到服务器。 该引用字符串由处理回发的指定控件和一个附加事件信息的字符串参数定义。

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

参数

control
Control

处理回发的服务器控件。

argument
String

传递给服务器控件的参数。

返回

一个字符串,将其视为客户端脚本时,将启动回发。

属性

示例

   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
   
   <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
End Class

注解

此方法已被否决。 请改用 GetPostBackEventReference 类中的 ClientScriptManager 方法。

另请参阅

适用于