HttpResponseSubstitutionCallback Delegat

Definicja

Reprezentuje metodę, która obsługuje podstawianie po pamięci podręcznej.

public delegate System::String ^ HttpResponseSubstitutionCallback(HttpContext ^ context);
public delegate string HttpResponseSubstitutionCallback(HttpContext context);
type HttpResponseSubstitutionCallback = delegate of HttpContext -> string
Public Delegate Function HttpResponseSubstitutionCallback(context As HttpContext) As String 

Parametry

context
HttpContext

Element HttpContext zawierający informacje o żądaniu HTTP dla strony z kontrolką, która wymaga podstawienia po buforze.

Wartość zwracana

Zawartość wstawiona do buforowanej odpowiedzi przed wysłaniem do klienta.

Przykłady

W poniższym przykładzie kodu pokazano, jak programowo dodać kontrolkę Substitution do strony internetowej z pamięcią podręczną danych wyjściowych. Po załadowaniu strony bieżąca data i godzina są wyświetlane użytkownikowi w etykiecie. Ta sekcja strony jest buforowana i aktualizowana co 60 sekund. Po wykonaniu kontrolki Substitution wywołuje metodę GetCurrentDateTime , która musi być zgodna z podpisem delegata HttpResponseSubstitutionCallback . Ciąg zwracany przez metodę GetCurrentDateTime jest wyświetlany użytkownikowi. Ta sekcja strony nie jest buforowana i jest aktualizowana za każdym razem, gdy strona jest odświeżona. Właściwość MethodName kontrolki Substitution pobiera lub ustawia nazwę metody wywołania zwrotnego.

<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#">  
  
  void Page_Load(object sender, System.EventArgs e)
  {
    // Programmatically create a Substitution control.
    Substitution Substitution1 = new Substitution();
    
    // Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime";
    
    // Add the Substitution control to the controls
    // collection of PlaceHolder1.
    PlaceHolder1.Controls.Add (Substitution1);        

    // Display the current date and time in the label.
    // Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString();    
  }
  
  // The Substitution control calls this method to retrieve
  // the current date and time. This section of the page
  // is exempt from output caching. 
  public static string GetCurrentDateTime (HttpContext context)
  {
    return DateTime.Now.ToString ();
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="VB">  
  
  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Programmatically create a Substitution control.
    Dim Substitution1 As New Substitution
    
    ' Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime"
    
    ' Add the Substitution control to the controls
    ' collection of PlaceHolder1.
    PlaceHolder1.Controls.Add(Substitution1)
    
    ' Display the current date and time in the label.
    ' Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString()
  End Sub
  
  ' The Substitution control calls this method to retrieve
  ' the current date and time. This section of the page
  ' is exempt from output caching. 
  Shared Function GetCurrentDateTime(ByVal context As HttpContext) As String
    Return DateTime.Now.ToString()
  End Function
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution Constructor Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>

Uwagi

Delegat HttpResponseSubstitutionCallback , w połączeniu WriteSubstitution z metodą , jest używany do renderowania zawartości po pamięci podręcznej dla Substitution kontrolek i AdRotator .

Dla kontrolki Substitution użyj MethodName właściwości , aby określić nazwę metody wywołania zwrotnego do wywołania podczas Substitution wykonywania kontrolki. Wybrana metoda wywołania zwrotnego musi być metodą statyczną na stronie lub w kontrolce użytkownika, która zawiera kontrolkę Substitution . Podpis metody wywołania zwrotnego musi być zgodny z podpisem HttpResponseSubstitutionCallback delegata HttpContext , który przyjmuje parametr i zwraca ciąg.

W przypadku kontrolki AdRotator renderowanie jest niezależne od buforowania strony, chyba że dla zdarzenia zostanie podana AdCreated procedura obsługi zdarzeń. Jeśli program obsługi zdarzeń nie AdCreated istnieje, podstawianie po pamięci podręcznej jest używane do renderowania AdRotator zawartości.

Metody rozszerzania

GetMethodInfo(Delegate)

Pobiera obiekt reprezentujący metodę reprezentowaną przez określonego delegata.

Dotyczy

Zobacz też