Hi
First, Please read the entire post before you provide answer...
I am trying to create a page with image upload. After the upload, a image thumbnail of the uploaded images are shown below the file upload controls.
Here is what I am doing now...
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (FileUploadPhoto.PostedFil
e != null)
{
AddImagePreviewControls();
}
}
}
...
protected void AddImagePreviewControls()
{
if (FileUploadPhoto.HasFile)
{
HiddenFieldPhotoCount.Valu
e = Convert.ToString((Convert.
ToInt32(Hi
ddenFieldP
hotoCount.
Value)) + 1);
String imageControlId = HiddenFieldPhotoCount.Valu
e;
PlaceHolder ph = new PlaceHolder();
ph.ID = "PlaceHolderPhoto" + imageControlId;
PanelPhotos.Controls.Add(p
h);
LinkButton lb = new LinkButton();
lb.ID = "LinkButtonPhoto" + imageControlId;
lb.Text = "delete";
lb.Attributes.Add("OnClick
", "DynamicLinkButtonPhoto_On
Click");
PanelPhotos.Controls.Add(l
b);
}
}
...
// an on_click event has code to upload the photos & other required stuff after which i call a method to set values for created controls, the method shown below
protected void SetImagePreview(String iName)
{
String imageControlId = HiddenFieldPhotoCount.Valu
e;
PlaceHolder currentPH = (PlaceHolder)WizardNewProf
ile.FindCo
ntrol("Pla
ceHolderPh
oto" + imageControlId);
LinkButton currentLB = (LinkButton)WizardNewProfi
le.FindCon
trol("Link
ButtonPhot
o" + imageControlId);
String iUrl = Request.ApplicationPath.To
String() + "/Photos/folder/" + iName;
currentPH.Controls.Add(new
LiteralControl("<img src=\"" + iUrl + "\" width=\"50px\" />"));
currentLB.CommandArgument = iName;
}
What happens is that though everything works fine, on postback, the image(placeholder) and linkbutton disappears.
What am I doing wrong? please guide me...
Start Free Trial