Based on dropdown i'm getting value and need to use for ajax file upload, now the problem is that i'm getting value properly, i'm using two ajax file upload(ajaxUpload1_OnUploadComplete & ajaxUpload2_OnUploadComplete), whenever i click the upload control for uploading files from the both the control goes to one upload method(ajaxUpload1_OnUploadComplete) only for uploading files. I need a solution for this. Thanks in advance.
In .cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Value"] = DropDownList1.SelectedItem.Text;
}
protected void ajaxUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
String value = Session["Value"].ToString();
}
protected void ajaxUpload2_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
String value1 = Session["Value"].ToString();
}
In .aspx
<asp:AjaxFileUpload ID="AjaxFileUpload1" AllowedFileTypes="jpg,jpeg" MaximumNumberOfFiles="10" ThrobberID="1" ContextKeys="1" OnUploadComplete="ajaxUpload1_OnUploadComplete" runat="server"/>
<asp:AjaxFileUpload ID="AjaxFileUpload2" AllowedFileTypes="jpg,jpeg" ThrobberID="2" MaximumNumberOfFiles="10" ContextKeys="2" OnUploadComplete="ajaxUpload2_OnUploadComplete" runat="server" />
I think it a bug in the AjaxFileUpload I asked about this before and never got any reply except work a workaround here is the solution for this.
private string ContextKey = "";
public AjaxFileUpload()
: base(true, HtmlTextWriterTag.Div)
{
if (HttpContext.Current.Items["lastAjaxFileUploadContextKey"] == null)
{
HttpContext.Current.Items["lastAjaxFileUploadContextKey"] = 1;
}
else
{
HttpContext.Current.Items["lastAjaxFileUploadContextKey"] = (int)HttpContext.Current.Items["lastAjaxFileUploadContextKey"] + 1;
}
ContextKey = HttpContext.Current.Items["lastAjaxFileUploadContextKey"].ToString();
}