Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my design like below

[fileuploadcontrol]
[upload button]
[upload label]

[displayImage button]

In runtime I added placeholder to fileupload control,upload button,upload label.add displayImage button to webpage.when i click the displayImage button it will display fileupload control & upload button.after selecting file path i click the upload button it will upload the file & display the labelas uploaded filename is soandso.but problem is after selecting the path when i click the upload button automatically placeholder were closed.what is the problem give solution.very urgent.please don't give code in vb.net
Posted
Comments
Abhinav S 5-Jul-10 10:44am    
You have not provided any code. It will not be possible for anyone to help you unless you paste some code here.
#realJSOP 5-Jul-10 10:46am    
I deleted the other version of this. If you want to change the question a little, then edit the one that's already here.

1 solution

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)
        {
            //in display PlaceHolder Content after PostBack
            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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900