Check this code. i answer this type of question yesterday in dotnetspider.
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="placeholderissue.aspx.cs" Inherits="placeholderissue" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Display1"
onclick="Button1_Click" />
<asp:Button ID="Button2"
runat="server" Text="Display2" onclick="Button2_Click" />
<br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> <br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class placeholderissue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (Display1)
{
if (PlaceHolder1.FindControl("Calendar1") == null)
{
Calendar calender1 = new Calendar();
calender1.ID = "Calendar1";
PlaceHolder1.Controls.Add(calender1);
PlaceHolder1.Visible = true;
}
}
if (Display2)
{
if (PlaceHolder2.FindControl("FileUpload1") == null)
{
FileUpload fup = new FileUpload();
fup.ID = "FileUpload1";
PlaceHolder2.Controls.Add(fup);
PlaceHolder2.Visible = true;
}
}
}
else
{
PlaceHolder1.Visible = false;
PlaceHolder2.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (PlaceHolder1.FindControl("Calendar1") == null)
{
Calendar calender1 = new Calendar();
calender1.ID = "Calendar1";
PlaceHolder1.Controls.Add(calender1);
PlaceHolder1.Visible = true;
Display1 = true;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (PlaceHolder2.FindControl("FileUpload1") == null)
{
FileUpload fup = new FileUpload();
fup.ID = "FileUpload1";
PlaceHolder2.Controls.Add(fup);
PlaceHolder2.Visible = true;
Display2 = true;
}
}
public bool Display1 {
get
{
object o = ViewState["_Display1"];
if (o == null)
return false;
else
return (bool)ViewState["_Display1"];
}
set
{
ViewState["_Display1"] = value;
}
}
public bool Display2
{
get
{
object o = ViewState["_Display2"];
if (o == null)
return false;
else
return (bool)ViewState["_Display2"];
}
set
{
ViewState["_Display2"] = value;
}
}
}
%>]]>