I have a very simple page that lists the contents of a folder in a GridView and allows a file to be uploaded using the AjaxFileUpload control. The only problem is that after the file is uploaded the GridView does not refresh to display the uploaded file.
I have verified that the GridView does indeed get updated -- the RowDataBound handler shows the correct information, but the display does not get refreshed. Any suggestions would be greatly appreciated!
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="dirtest.aspx.vb" Inherits="FileUpload" %>
Imports System.IO
Partial Class FileUpload
Inherits System.Web.UI.Page
Const myPath = "~/repository/EXC00013"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call LoadFolder(myPath)
End Sub
Protected Sub FileUpload_OnUploadComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AjaxFileUploadEventArgs)
DirectCast(sender, AjaxControlToolkit.AjaxFileUpload).SaveAs(Server.MapPath(myPath) & "\" & Path.GetFileName(e.FileName))
Call LoadFolder(myPath)
End Sub
Private Sub LoadFolder(ByVal virtualFolderPath As String)
Dim folder As New DirectoryInfo(Server.MapPath(virtualFolderPath))
Dim fileList As FileInfo() = folder.GetFiles()
GridView1.DataSource = fileList
GridView1.DataBind()
End Sub
End Class
Thanks!
hi MJEdelman,
According to your description, you have verified that the GridView does indeed get updated but the GridView display does not get refreshed.
I would suggest you need to ensure the AjaxFileUpload run correctly after UploadCompleted.
If it is ok, you can try the follow workaround :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Call LoadFolder(myPath)
End If
End Sub
i hope it helps you.
I did try that and it did not help. The only way to get the GridView to refresh is to do a full postback -- and I really want a partial postback.
hi MJEdelman,
I would suggest you
read the reference below for more information:
UpdatePanel + FileUpload + PostBackTrigger doesn't seem to work
http://forums.asp.net/t/1131013.aspx
Thank you for your response! I have tried that. The problem is that it does a full postback and I only want a partial postback. This seems like a seriou flaw in the AjaxFileUpload control...
You can try the follow workaround:
JavaScript :
function ClientUploadComplete(sender, args) {
if (sender._filesInQueue[sender._filesInQueue.length - 1]._isUploaded)
__doPostBack('UploadPanel', ''); // Do post back only after all files have been uploaded
}
Code Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Need to prevent normal stuff on ajaxFileUpload PostBack
if Not IsPostBack && Not IsCallback && Not AjaxFileUpload1.IsInFileUploadPostBack then
Call LoadFolder(myPath)
' Do normal stuff
End If
End Sub
if it is still not working for you , it maybe be flaw in the AjaxFileUpload control.
沒有留言:
張貼留言