i'm quite new developing for asp.net and found a problem i can't figure it out. My .aspx look like the follow:
<form action="#" class="" runat="server" >
<asp:DropDownList ID="ddlCombo" runat="server">
</asp:DropDownList>
</form>
<div class="clsbox-1" runat="server">
<div class="dropzone clsbox" id="mydropzone">
</div>
</div>
As you can see i have a dropdownlist that i will populate on page_load and a dropzone inside a div (i need to be this way).
<script>
Dropzone.autoDiscover = false;
$("#mydropzone").dropzone({
url: "WebForm1.aspx?param=1",
addRemoveLinks: true,
maxFilesize: 0.5,
dictDefaultMessage: 'drag and drop',
dictResponseError: 'Error uploading file!'
});
<script>
this is the script that make div like a dropzone, i'm not sure if the url is right though. The problems comes when in the page_load part, since i need to populate the dropdownlist on page load, when i try to upload a file via dropzone it will be sent as postback and enter in the 'if' and populate again the combobox, reseting the value that was selected.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
loadCombo(); //populate ddlCombo
}
string aux = ddlCombo.SelectedValue.ToString();//this will have the first item
//processing file...
}
Please let me know if there is any fancy way to do this because i can't figure it out!
EDIT: I don't understand why if i send within a form it work as intended:
<form action="#" class="dropzone" runat="server" >
<asp:DropDownList ID="ddlCombo" runat="server">
</asp:DropDownList>
<div class="clsbox-1 " id="mydropzone" runat="server">
<div class="clsbox" >
</div>
</div>
</form>
When i upload a file here it doesn't send as post back. Thx you!
Your dropzone url parameter should be to a different page/httphandler/controller you have created to accept the upload and save it to a file (or whatever you want to do with it). You could technically use the page you're currently on, but it'd be a little trickier in your situation as you'd need to detect what caused the postback and handle appropriately (ie don't reset the dropdown).
I would recommend using an HttpHandler instead of a normal page for receiving the files. Here's an example of one.