Hi,
Need some advice on how best to resolve a issue with a page I am designing. I am developing a site using ASP.NET 2.0 with C# code behind.
I have a page that allows the user to upload 3 images to the server and then displays the uploaded images on the page. To do this I have placed 3 image buttons on the page, when clicked they execute this function:
This displays a popup window showing a aspx page that allows the user to upload a image. I am using the .NET 2.0 control called FileUpload to handle the file and save it to the server using a postback as per Microsofts direction:
Now what I want to do the following:
1. When the user hits confirm (which causes a postback and uploads the image as above) - close the popup window posting back (or some other way) the full filepath+name from the FileUpload control to a hidden field on the main aspx page.
2. When the above occurs the main page's image button takes the value stored in the hidden field and loads the image as per the filepath+name.
Simple enough but I am finding about a dozen ways of doing something similar i.e. returning a value from the popup window and I really don't know which is the right way of doing it.
Thanks in advance,
Fz
Need some advice on how best to resolve a issue with a page I am designing. I am developing a site using ASP.NET 2.0 with C# code behind.
I have a page that allows the user to upload 3 images to the server and then displays the uploaded images on the page. To do this I have placed 3 image buttons on the page, when clicked they execute this function:
Code:
private void PopUp()
{
// use the StringBuilder class to create our JS code block
// create a new instance of StringBuilder
StringBuilder sb = new StringBuilder();
// build the string containing the JS script code
sb.Append("<script type='text/javascript' language='javascript'>");
sb.Append("window.open('./Dialogs/FileUploadForm.aspx', 'CustomPopUp', ");
sb.Append("'width=350, height=280, menubar=no, resizable=no');");
sb.Append("</script>");
// register with ClientScript
Type t = this.GetType();
if (!ClientScript.IsStartupScriptRegistered(t, "PopupScript"))
{
ClientScript.RegisterStartupScript(t, "PopupScript", sb.ToString());
}
}
This displays a popup window showing a aspx page that allows the user to upload a image. I am using the .NET 2.0 control called FileUpload to handle the file and save it to the server using a postback as per Microsofts direction:
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/Uploads/");
if (BIUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(BIUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".gif", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
BIUpload1.PostedFile.SaveAs(path
+ BIUpload1.FileName);
ImageUploadStatus.Text = "File uploaded!";
}
catch (Exception ex)
{
ImageUploadStatus.Text = "File could not be uploaded. \n " + ex.ToString();
}
}
else
{
ImageUploadStatus.Text = "Cannot accept files of this type.";
}
}
}
Now what I want to do the following:
1. When the user hits confirm (which causes a postback and uploads the image as above) - close the popup window posting back (or some other way) the full filepath+name from the FileUpload control to a hidden field on the main aspx page.
2. When the above occurs the main page's image button takes the value stored in the hidden field and loads the image as per the filepath+name.
Simple enough but I am finding about a dozen ways of doing something similar i.e. returning a value from the popup window and I really don't know which is the right way of doing it.
Thanks in advance,
Fz