Monday, September 20, 2010

asp.net Substitution and Caching example::





SubstitutionExample.aspx 

<%@ Page Language="C#" %>
<!-<%@ OutputCache Duration="300" 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">
    static string myRandomNumber(HttpContext context) {
        int myNumber = new System.Random().Next(100, 500);
        return myNumber.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net Substitution and Caching example: how to use Substitution Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1 style="color:Fuchsia">Substitution Example</h1>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        Page Cached Time:
        <h2 style="color:Teal">
            <%= DateTime.Now.ToLongTimeString() %>
        </h2>
        Current Time:
        <h2 style="color:Navy">
            <%= DateTime.Now.ToLongTimeString() %>
        </h2>
        <hr />
        Substitition Control Zone [Random Number]
        <h1 style="color:Red">
            <asp:Substitution ID="Substitution1" runat="server" MethodName="myRandomNumber" />
        </h1>
    </div>
    </form>
</body>
</html>

   

No comments:

Post a Comment