PlaceHolder Example in ASP.NET using C#

PlaceHolder Example in ASP.NET using C#


Posted in : ASP.Net Posted on : November 26, 2010 at 6:24 PM Comments : [ 0 ]

In this article we will introduce with PlaceHolder control in ASP.NET using C#.

PlaceHolder Example in ASP.NET using C#

PlaceHolder Web server control in ASP.NET is used to added the controls at run time. In this example we take four PlaceHolder and each PlaceHolder contains a hyperlink. We create a HyperLink in C# and added to it at runtime.

PlaceHolder.aspx (Design Page):

PlaceHolder.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" 
AutoEventWireup="true" CodeFile="PlaceHolder.aspx.cs" Inherits="PlaceHolder" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
 Runat="Server">
<div>
<h2 style="color:Green">PlaceHolder in ASP.NET 4 , C#</h2>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<br />
<br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
<br />
<br />
<asp:PlaceHolder ID="PlaceHolder3" runat="server"></asp:PlaceHolder>
<br />
<br />
<asp:PlaceHolder ID="PlaceHolder4" runat="server"></asp:PlaceHolder>
</div>
</asp:Content>

PlaceHolder.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;
using System.Web.UI.WebControls.WebParts;
public partial class PlaceHolder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HyperLink hyperlink1 = new HyperLink();
hyperlink1.Text = "Devmanuals";
hyperlink1.NavigateUrl = "http://www.devmanuals.com/";
PlaceHolder1.Controls.Add(hyperlink1);
HyperLink hyperlink2 = new HyperLink();
hyperlink2.Text = "Google";
hyperlink2.NavigateUrl = "http://www.google.com/";
PlaceHolder2.Controls.Add(hyperlink2);
HyperLink hyperlink3 = new HyperLink();
hyperlink3.Text = "Yahoo";
hyperlink3.NavigateUrl = "http://www.yahoo.com/";
PlaceHolder3.Controls.Add(hyperlink3);
HyperLink hyperlink4 = new HyperLink();
hyperlink4.Text = "Roseindia";
hyperlink4.NavigateUrl = "http://www.roseindia.net/";
PlaceHolder4.Controls.Add(hyperlink4);
}
}

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics