0

I am using an AjaxFileUpload for multiple file upload. It is working, but I want to change the destination with the value in a textbox. The code is below which is in the AjaxFileUpload1_onUploadComplete method:

string myDir= myDirTextBox.Text.Trim();
AjaxFileUpload1.SaveAs(Server.MapPath("../allarticles/"+ myDir+"/"+e.FileName));

I debug the project and write a name in the myDirTextBox. Then when I click the Upload File button the value of this textbox is always null. That's why I can't change the destination dynamically. I have read this article but it is not clear: upload multiple files with ajaxFileUpload with different file ids

What is the problem and how can I solve it?

batman567
  • 826
  • 2
  • 12
  • 23
mkarakoc04
  • 21
  • 3

1 Answers1

1

When server event occurs the page goes through complete page lifecycle. That means your code deals with new, uninitialized version of a page which is not related in any way with the page you see in a browser.

To save the value of a textbox and utilize it later you need to write some code to store this value between page requests. This can be simple JavaScript code attached to Upload button, that posts textbox value with AJAX to a server. Server, in turn, will store this value in session or another persistent storage.

Mikhail Tymchuk
  • 886
  • 4
  • 8
  • Do you mean; define a javascript function that occurs on page submit and send the value of myDirTextBox.Text to server? I don't know how can I do this. :( – mkarakoc04 Feb 05 '16 at 11:54
  • Yes, that's what I mean. You can use [jQuery](https://jquery.com/) library to get textbox value (there are plenty examples in Internet showing how to do it) and then send it with [$.ajax()](http://api.jquery.com/jQuery.ajax/) or [$.post()](http://api.jquery.com/jQuery.post/) methods. – Mikhail Tymchuk Feb 10 '16 at 08:41