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 ((PlaceHolder1.FindControl("FileUpload1") == null) && (PlaceHolder1.FindControl("Button2") == null) && (PlaceHolder1.FindControl("Label1") == null))
{
FileUpload fup = new FileUpload();
fup.ID = "FileUpload1";
Button btn = new Button();
btn.ID = "Button2";
btn.Text = "Upload";
btn.Click += new EventHandler(btn_Click);
Label lbl = new Label();
lbl.ID = "Label1";
PlaceHolder1.Controls.Add(fup);
PlaceHolder1.Controls.Add(btn);
PlaceHolder1.Controls.Add(lbl);
}
}
else
{
FileUpload fup = new FileUpload();
fup.ID = "FileUpload1";
Button btn = new Button();
btn.ID = "Button2";
btn.Text = "Upload";
btn.Click += new EventHandler(btn_Click);
Label lbl = new Label();
lbl.ID = "Label1";
PlaceHolder1.Controls.Add(fup);
PlaceHolder1.Controls.Add(btn);
PlaceHolder1.Controls.Add(lbl);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((PlaceHolder1.FindControl("FileUpload1") == null) && (PlaceHolder1.FindControl("Button2") == null) && (PlaceHolder1.FindControl("Label1") == null))
{
FileUpload fup = new FileUpload();
fup.ID = "FileUpload1";
Button btn = new Button();
btn.ID = "Button2";
btn.Text = "Upload";
btn.Click += new EventHandler(btn_Click);
Label lbl = new Label();
lbl.ID = "Label1";
PlaceHolder1.Controls.Add(fup);
PlaceHolder1.Controls.Add(btn);
PlaceHolder1.Controls.Add(lbl);
}
}
protected void btn_Click(object sender, EventArgs e)
{
if ((PlaceHolder1.FindControl("FileUpload1") != null)&&(PlaceHolder1.FindControl("Label1") != null))
{
FileUpload fup = (FileUpload)PlaceHolder1.FindControl("FileUpload1");
Label lbl = (Label)PlaceHolder1.FindControl("Label1");
if ((fup != null) && (lbl != null))
{
string _savePath=Server.MapPath(Guid.NewGuid().ToString()+System.IO.Path.GetExtension(fup.FileName));
fup.SaveAs(_savePath);
lbl.Text=fup.FileName;
}
}
}
}
<%@ 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:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> <br />
<div>
</form>
</body>
</html>