Substitution Example in ASP.NET using C#

Substitution Example in ASP.NET using C#


Posted in : ASP.Net Posted on : November 27, 2010 at 5:21 PM Comments : [ 0 ]

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();
}
}

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics