Onlineatoz.net | ToolBox Standard Control Substitution

ToolBox Standard Control Substitution

Substitution Web Server Control

in ASP.NET environment,This article explains you how to work with Substitution Web Control.The Substitution control specifies a section on an output-cached Web page that is exempt from caching. Use the Substitution control to specify a section on an output-cached Web page where you want dynamic content substituted for the control.

Dynamically Updating Portions of a Cached Page

in a Web application environment,the output of the page is cached if an ASP.NET page is cached. On the first request, the page runs and caches its output. On subsequent requests, the request is fulfilled from the cache and code on the page does not run.

You can use the Substitution control to insert dynamic content into the cached page. The Substitution control does not render any markup.he method called by the Substitution control must meet the following criteria:

  • It is defined as a static method
  • It accepts a parameter of type HttpContext.
  • It returns a value of type String.

Note that other controls on the page are not accessible to the Substitution control—that is, you cannot examine or change the value of other controls. However, the code does have access to the current page context using the parameter passed to it.

the following code snippets demonstrates the above purposes.

in .aspx.cs page,

void Page_Load()
    {
        Label1.Text = DateTime.Now.ToString();
    }
    
    public static String GetTime(HttpContext context)
    {
      return DateTime.Now.ToString();
    }

    

in .aspx page,

<html>
<head id="Head1" runat="server"></head>
<body>
    <form id="form2" runat="server">
    <div>
    <p>
    <asp:Label runat="server" ID="Label1" />
    </p>
    <p>
    <asp:Substitution runat="server" 
        ID="Substitution1" 
        MethodName="GetTime" />
    </p>
    <p>
    <asp:Button runat="server" ID="Button1" Text="Submit"/>
    </p>
    </div>
    </form>
</body>
</html>

    
 
Related Links

Posted by: Admin
Posted on: 9/13/2011 at 7:43 PM
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed