In this article we will introduce with Substitution control in ASP.NET using C#.
Substitution Example in ASP.NET using C#
Substitution control in ASP.NET is used to call a method that's return a string in an output-cached page. A developer can place a substitution on page and use string method for CallBack. In this example the simple time label shows the time. But in the Substitution it call the GetDate method for showing the time.
Substitution.aspx (Design page):
Substitution.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="Substitution.aspx.cs" Inherits="Substitution" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> Substitution in ASP.NET 4 , C#</h2> Time: <% = DateTime.Now.ToString() %> <br /> <br /> <strong>Time in Substitution:</strong> <asp:Substitution ID="Substitution1" runat="server" MethodName="GetTime" /> </div> </asp:Content>
Substitution.aspx.cs (C# code file);
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Substitution : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected static string GetTime(HttpContext context) { return DateTime.Now.ToString(); } }
[ 0 ] Comments