ClientScriptManager.GetPostBackClientHyperlink Método

Definición

Obtiene una referencia, con javascript: anexado al principio, que se puede utilizar en un evento de devolución de datos del cliente al servidor.

Sobrecargas

GetPostBackClientHyperlink(Control, String)

Obtiene una referencia, con javascript: anexado al principio, que se puede utilizar en un evento de devolución de datos del cliente al servidor para el control especificado y con los argumentos de evento especificados.

GetPostBackClientHyperlink(Control, String, Boolean)

Obtiene una referencia, con javascript: anexado al principio, que se puede utilizar en un evento de devolución de datos del cliente al servidor para el control especificado y con los argumentos de evento especificados y, también, con una indicación booleana de si se debe registrar la devolución de datos para realizar la validación del evento.

GetPostBackClientHyperlink(Control, String)

Obtiene una referencia, con javascript: anexado al principio, que se puede utilizar en un evento de devolución de datos del cliente al servidor para el control especificado y con los argumentos de evento especificados.

C#
public string GetPostBackClientHyperlink (System.Web.UI.Control control, string argument);

Parámetros

control
Control

Control de servidor que va a procesar el valor devuelto.

argument
String

Parámetro pasado al control de servidor.

Devoluciones

String

Cadena que representa una llamada de JavaScript a la función de postback que incluye el id. del control de destino y los argumentos del evento.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del GetPostBackClientHyperlink método . El control personalizado, MyControl, implementa la IPostBackEventHandler interfaz . Cuando se hace clic en el elemento delimitador HTML de la página, se invoca el RaisePostBackEvent método del control personalizado.

ASP.NET (C#)
<%@ 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>

El ejemplo de código siguiente tiene la misma funcionalidad que la anterior, excepto que, en lugar de un control personalizado, la Page clase implementa la IPostBackEventHandler interfaz .

ASP.NET (C#)
<%@ 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>

Comentarios

El uso del GetPostBackEventReference método requiere el control que controla el postback para implementar la IPostBackEventHandler interfaz . Para implementar la IPostBackEventHandler interfaz para , Pageuse la @ Implements directiva .

Consulte también

Se aplica a

.NET Framework 4.8 e outras versións
Produto Versións
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

GetPostBackClientHyperlink(Control, String, Boolean)

Obtiene una referencia, con javascript: anexado al principio, que se puede utilizar en un evento de devolución de datos del cliente al servidor para el control especificado y con los argumentos de evento especificados y, también, con una indicación booleana de si se debe registrar la devolución de datos para realizar la validación del evento.

C#
public string GetPostBackClientHyperlink (System.Web.UI.Control control, string argument, bool registerForEventValidation);

Parámetros

control
Control

Control de servidor que va a procesar el valor devuelto.

argument
String

Parámetro pasado al control de servidor.

registerForEventValidation
Boolean

Es true para registrar el evento postback para su validación; es false para no registrarlo.

Devoluciones

String

Cadena que representa una llamada de JavaScript a la función de postback que incluye el id. del control de destino y los argumentos del evento.

Comentarios

El uso del GetPostBackEventReference método requiere el control que controla el postback para implementar la IPostBackEventHandler interfaz . Para implementar la IPostBackEventHandler interfaz para , Pageuse la @ Implements directiva .

Consulte también

Se aplica a

.NET Framework 4.8 e outras versións
Produto Versións
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8