ASP.NET - File upload control postback problem

Asked By kiruba .e on 16-May-11 02:29 AM
Hi,

I hav one file upload control and checkboxes etc in my page.  And i m checking the file lenth while i saving.


What my problem is,

When i click the checkbox due to the postback event, the fileupload control values(path ) cleared.

Please give solution.
dipa ahuja replied to kiruba .e on 16-May-11 02:34 AM
So set the AutoPostBack = false for your CheckBox..


or if its neccessary to put it true then store the path of fileUpload in Session

Session["path"] = FileUpload1.FileName;
TSN ... replied to kiruba .e on 16-May-11 02:34 AM
hi...

You can try to persist file upload value in hidden field between async post-backs using asp.net ajax event handlers.

Sys.WebForms.PageRequestManager.instance.add_beginRequest(BeginRequestHandler)
Sys.WebForms.PageRequestManager.instance.add_endRequest(EndRequestHandler)

function BeginRequestHandler(sender, args) {
var fileUpload = document.getElementById('fileUpload');
var hiddenUpload = document.getElementById('hiddenUpload');
hiddenUpload.value = fileUpload.value;
}

function EndRequestHandler(sender, args) {
var fileUpload = document.getElementById('fileUpload');
var hiddenUpload = document.getElementById('hiddenUpload');
fileUpload.value = hiddenUpload.value;
}

Reena Jain replied to kiruba .e on 16-May-11 02:36 AM
hi,

for this you have to prevent from whole page postback and you need to use Ajax, so when you will sent checkbox to server only that control will be postback on server.


Hope this will help you