I have a RadAsyncUpload control in a RadWindow, but can't get it to save the file. I previously had the same upload control dynamically added on the page (outside the window) and it was working fine. Can someone help me with this?
First of all, I have a RadWindow defined:
<
telerik:RadWindow
ID
=
"winUploadImage"
runat
=
"server"
VisibleOnPageLoad
=
"false"
OnClientShow
=
"windowLoad"
VisibleStatusbar
=
"false"
AutoSize
=
"false"
Width
=
"451"
Height
=
"275"
>
<
ContentTemplate
>
</
ContentTemplate
>
</
telerik:RadWindow
>
Next, I have a dynamically created RadAsyncUpload Control that is created and added to the window:
protected void BtnUpload_Click(object sender, EventArgs e)
{
winUploadImage.ContentContainer.Controls.Add(new LiteralControl("<
div
class=\"quotebox\"><
table
class=\"quotetext\"><
tr
><
td
colspan=\"2\" class=\"quotetext\">"
+ "</
td
></
tr
><
tr
><
td
class=\"quotetext\">Do you want to use a previously uploaded image?" + "</
td
>"
+ "</
tr
>"
+ "</
table
></
div
>"
));
RadButton clickedButton = new RadButton();
clickedButton = (RadButton)sender;
RadAsyncUpload upload = new RadAsyncUpload();
upload.ID = "rauChoice";
upload.Attributes.Add("runat", "server");
upload.Attributes.Add("type", clickedButton.Attributes["type"]);
upload.Attributes.Add("subtype", clickedButton.Attributes["subtype"]);
//upload.Height = Unit.Parse("86px");
//upload.Width = Unit.Parse("1px");
upload.TargetFolder = "~/App_Images/uploads";
upload.TemporaryFolder = "~/App_Data/RadUploadTemp";
upload.FileUploaded += new FileUploadedEventHandler(ChangeFilename);
upload.OnClientFileUploading = "uploading_file";
upload.MaxFileInputsCount = 1;
upload.MaxFileSize = 5000000; // 5 MB
winUploadImage.ContentContainer.Controls.Add(imgAdd);
winUploadImage.ContentContainer.Controls.Add(upload);
winUploadImage.Modal = false;
winUploadImage.Behaviors = Telerik.Web.UI.WindowBehaviors.Close;
//winUploadImage.Top = 650;
//winUploadImage.Left = 825;
winUploadImage.OffsetElementID = divOptions.ClientID;
winUploadImage.Top = 40;
winUploadImage.Left = -25;
winUploadImage.VisibleOnPageLoad = true;
}
When the files is uploaded, it should call this function
protected void ChangeFilename(object sender, FileUploadedEventArgs e)
{
try
{
RadAsyncUpload uploadMod = new RadAsyncUpload();
uploadMod = (RadAsyncUpload)sender;
string targetFolder = uploadMod.TargetFolder;
string newName =
uploadMod.Attributes["type"] + "!"
+ uploadMod.Attributes["subtype"] + "!"
+ DateTime.Now.ToString("yyyyMMddHHmmssfff")
;
Session[uploadMod.ID] = newName + e.File.GetExtension();
e.File.SaveAs(Path.Combine(Server.MapPath(targetFolder), newName + e.File.GetExtension()));
}
catch (Exception ex)
{
throw ex;
}
}
When a button inside the window is pressed, the page posts back, but the file is not uploaded (it is not saved in the target folder and the ChangeFilename funtion is not called).
How can I get the file to upload correctly?