2014年7月13日 星期日

[RESOLVED] Iframe in update panel not updating


Hi, I am facing this problem that after I upload a new pdf file the iframe in the ajax update panel does not get updated until I did a refresh manually.


I have did a simple dummy to show the error: 


.aspx:


 









Sec Sch Testimonial















.aspx.cs:


protected void UploadButton_Click(object sender, EventArgs e)

{

string admin_number = Label1.Text;

if (FileUpload.HasFile) //check for exist file

{

try

{

string ext = Path.GetExtension(FileUpload.FileName); //check for file extension

if (ext == ".pdf")

{

//string filename = Path.GetFileName(FileUpload.FileName);

FileUpload.SaveAs(Server.MapPath("~/pdf/") + admin_number + ".pdf"); //upload the file to the storage

}

}

catch (Exception ex)

{

}

}

//LinkButton1.Click();

UpdatePanel1.Update();

//refreshContent(admin_number);

//UpdatePanel1.Update();

//pdf_viewer.Attributes.Add("src", "images/testimonial/" + lblAdminNo.Text + ".pdf");


}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

Label1.Text = DropDownList1.SelectedItem.Value.ToString();

UpdatePanel1.Update();

}

protected void LinkButton1_Click(object sender, EventArgs e)

{

string file = Server.MapPath("~/pdf/" + Label1.Text + ".pdf");

if (System.IO.File.Exists(file))

{

pdf_viewer.Attributes.Add("src", "pdf/" + Label1.Text + ".pdf");

}

else

{

pdf_viewer.Attributes.Add("src", "http://www.google.com");

}

UpdatePanel1.Update();

}



Hi,


According to your description and the code you provided, you put the upload control into UpdatePanel, so far as I know, as you place FileUpload control in UpdatePanel and try to upload the file asynchronously using the
HasFile property of the FileUpload Control will always be false. So we will add
PostBackTrigger.


There is a demo, I have tested it ok, please refer to the code below:














<%----%>



The code behind:


 protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{

string fileName = FileUpload1.FileName;
FileUpload1.SaveAs("D://Images/" + fileName);
//img.ImageUrl = "~/Images/" + fileName;
Label1.Text = "ok";
}

}

protected void Button2_Click(object sender, EventArgs e)
{
string fileName = FileUpload1.FileName;
if (FileUpload1.HasFile)
{


FileUpload1.SaveAs("D://Images/" + fileName);
// img.ImageUrl = "~/Images/" + fileName;
}
Label1.Text = fileName;

}

Hope it's useful for you.


Best Regards,


Michelle Ge



沒有留言:

張貼留言