Rank: Newbie Groups: Member
Joined: 6/2/2007 Posts: 5
|
I have upgraded to the latest version: 2007.1.43 I am still having an issue with the OnFileUploaded event not firing after a successful upload. I get the 3 temp files loaded correctly, but the OnFileUploaded event does not fire until the user Logs Out of the web page. Please review my code, and see if there is any problem you can spot. The C# code I have written will execute correctly, but not until the user Logs Out. If they navigate to another page, from the File Upload page, it does not fire either. This is a problem. It is like the AJAXUploader needs the page to do a post back before it will fire the OnFileUploaded event. Any feedback is appreciated.
Code: C#
protected void Page_Load(object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname = "UploadScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
{
StringBuilder cstext = new StringBuilder();
cstext.Append("function AJAXUploader1_OnClientError(control, error, message) {");
//cstext.Append("alert(message);}");
cstext.Append("if (error == 'max_size_exceeded'); {");
cstext.Append("alert('The file exceeds the 100MB size limit. Only files under a 100MB are allowed.'); }}");
cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), true);
}
}
private void FileUpload_FileCopy(object sender, System.EventArgs e)
{
// After file is uploaded, rename it and move it to seperate directory.
EO.Web.AJAXPostedFile[] files = AJAXUploader1.PostedFiles;
string DestinationPath = @"c:\temp\Files\";
string SourcePath = @"c:\temp\";
string TempName = string.Empty;
string ClientName = string.Empty;
foreach (EO.Web.AJAXPostedFile file in files)
{
TempName += System.IO.Path.GetFileName(file.TempFileName);
ClientName += System.IO.Path.GetFileName(file.ClientFileName);
System.IO.File.Delete(DestinationPath + ClientName);
System.IO.File.Copy(SourcePath + TempName, DestinationPath + ClientName);
TempName = string.Empty;
ClientName = string.Empty;
}
AJAXUploader1.ClearPostedFiles();
}
Code: HTML/ASPX
<body bgcolor="#f8f8f8">
<form id="form1" runat="server">
<div class="header">
<Mine:Header ID="Header1" runat="server" />
</div>
<div class="nav_trail" style="left: 20px; top: 51px">
<a href="../../Default.aspx">Home</a><img src="../../images/nav_arrow.jpg" />File
Upload</div>
<div class="menu_options">
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Default.aspx"
Width="113px" />
</div>
<div class="content" style="position: absolute; font-family: Verdana; width: 750px;
left: 199px; top: 73px; height: 500px;">
<eo:AJAXUploader ID="AJAXUploader1" runat="server" Width="700px" Height="400px" TempFileLocation="c:\temp"
MaxDataSize="102400" OnFileUploaded="FileUpload_FileCopy" ClientSideOnError="AJAXUploader1_OnClientError"
PostedFileLabelFormat="{posted_file_name} - ({posted_file_size}bytes)" Font-Size="10pt">
<LayoutTemplate>
<table border="0" cellpadding="2" cellspacing="0" style="width: 600px">
<tr>
<td style="width: 600px">
<asp:PlaceHolder ID="InputPlaceHolder" runat="server">Input Box Place Holder</asp:PlaceHolder>
</td>
</tr>
<tr>
<td align="right" style="width: 600px">
<asp:Button ID="UploadButton" runat="server" Text="Upload" />
</td>
</tr>
<tr>
<td style="width: 600px">
<eo:ProgressBar ID="ProgressBar" runat="server" ControlSkinID="Windows_XP" Height="14px"
Width="400px" RightToLeft="True">
</eo:ProgressBar>
</td>
</tr>
<tr>
<td style="width: 600px">
<asp:PlaceHolder ID="ProgressTextPlaceHolder" runat="server">Progress Text Place Holder
</asp:PlaceHolder>
</td>
</tr>
<tr>
<td align="right" style="width: 600px">
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</td>
</tr>
<tr>
<td style="text-align: left; width: 600px; height: 216px;">
<br />
<hr />
Listed below is the file(s) you have uploaded. If you made a mistake, use the delete
button to remove it.<br />
<br />
When you have uploaded all your files, please use the LOGOUT link in the upper right
hand corner. Thank You!<br />
<hr />
<br />
<asp:PlaceHolder ID="PostedFilesPlaceHolder" runat="server">Posted Files Place Holder
</asp:PlaceHolder>
</td>
</tr>
<tr>
<td align="right" style="text-align: left; width: 600px;">
<asp:Button ID="DeleteButton" runat="server" Text="Delete Selected Files" />
</td>
</tr>
</table>
<br />
</LayoutTemplate>
</eo:AJAXUploader>
<br />
<br />
<br />
</div>
<div style="width: 164px; height: 500px; position: absolute; left: 19px; top: 73px;
font-size: 10pt; font-family: Verdana; background-color: gainsboro; border-right: black thin solid;
padding-right: 3px; border-top: black thin solid; padding-left: 3px; padding-bottom: 3px;
border-left: black thin solid; padding-top: 3px; border-bottom: black thin solid;">
<br />
INSTRUCTIONS:<br />
<br />
<ul>
<li>Do not exceed 100 MB per file. </li>
</ul>
<p>
</p>
<ul>
<li>If you experience any problems, please click the 'Contact' link.</li>
</ul>
</div>
</form>
</body>
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
OnFileUploaded is fired when the page posts back. It has nothing to do with user logging out, it's just the page is posted back when user logs out.
For any server event to work, the page must be posted back. This is a general rule for ASP.NET ---- just like you put an asp:Button in the page, when you click the button, the page is posted back and the server side event is fired. This is rather straight forward because, unless you go back to the server side, nothing is going to happen on the server. After all your server side event handler runs on the server.
If you want OnFileUploaded to be fired immediately after the uploading is done, set the uploader's AutoPostBack to true. That way the page is automatically posted back once the uploading is done. Once again, the triggering point is page being posted back.
Thanks
|
Rank: Newbie Groups: Member
Joined: 6/2/2007 Posts: 5
|
Thank you for the quick answer. If it had been a snake, it would have bit me. ><
|