Variable not saved due to postback

I upload documents to a temporary folder using the Upload Control FileUploadComplete event, but I try to control what is uploaded to the temporary folder, so I can move it to the real application folder when the submit button is pressed,

I will upload the code that I have; hope some of them are helpful, thanks

//global list to store temp uploads
protected List<string> listTempImages = new List<string>();

protected void Page_Load(object sender, EventArgs e)
{
    //.....
}

//upload to temp method
protected void ucUploadFile_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
    e.CallbackData = SavePostedFiles(e.UploadedFile);
} 

string SavePostedFiles(UploadedFile uploadedFile)
{
    if (!uploadedFile.IsValid)
    {
        return string.Empty;
    }
    string strAttachmentFolderQuery = "CALL storedProcedure"; //
    DataTable dtFolderLocation = new DataTable();
    BasicUtilities.SelectCommand(ref strAttachmentFolderQuery, ref dtFolderLocation, sqlConn, true);

    string strFolderLocation = @dtFolderLocation.Rows[0]["ColumnName"].ToString();
    string strCallFolder = strFolderLocation + @"Temp\\";

    /** File doesn't exists, create folder and copy in new file */

    listTempImages.AddRange(uploadedFile.FileName.Split('.'));
    string strFileName = listTempImages[0];

    FileInfo fi = new FileInfo(strFileName);
    String timeStamp;

    timeStamp = DateTime.Now.ToString("yyyMMddhhmmss");
    string fullFileName = MapPath(strFolderLocation) + fi.Name;
    ucUploadFile.SaveAs(strCallFolder + fi.Name + "_" + timeStamp + "." + listTempImages[1]);

    //file_name_uploadTimeStamp.extention
    string fileLabel = fi.Name;
    string fileLength = uploadedFile.FileContent.Length / 1024 + "k";
    /** adding image to temp to ensure you can get it or delete it  */
    listTempImages.Add(strCallFolder + fi.Name + "_" + timeStamp); 

    return string.Format("{0} ({1})|{2}", fileLabel, fileLength, fi.Name);
}


protected void btnSubmit_Click1(object sender, EventArgs e)
{
    if (listTempImages != null)
    {
        /** Upload attachment to server */
        while (listTempImages.Count >0)
        {
            Upload(callID, reporterID);
        }
    }
    else
    {
        /** Upload panel doesn't have have a file */
    }
}

** EDIT

   <dx:ASPxButton ID="btnSubmit" runat="server" Text="Submit"
        ClientIDMode="AutoID"  
        onclick="btnSubmit_Click1" AutoPostBack="False">
        <ClientSideEvents Click="function(s, e) {
      if(document.getElementById('ucUploadFile_Input_0') == null){
    e.processonserver = false;
    $('#ucUploadFile_Add').click();
    e.processonserver = true;
       }
         }" />
   </dx:ASPxButton>
+3
source share
2 answers

HTTP - , postback. , postback ViewState. , , XML/database, ViewState , .

ViewState["listTempImages"] = listTempImages;

, ViewState

listTempImages = ViewState["listTempImages"] as List<string>;

, , , . . , , . , . wikipedia

- , ASP.NET . HTML , , , base64- . , MSDN

+2

, HTTP . , , .
viewstate , . . , xml . benifite xml

  ASP.NET

+1

All Articles