I have been trying to use the ContextKeys of AjaxControlToolkit's AjaxFileUpload control but I have been unsuccessful at setting the value at runtime. If I set it to a static value in the markup it works but when I try to set it from the code behind or in javascript it fails. I have looked at a few different examples of fixes but I haven't been able to solve the issue. Here is one example:
How can I use the ContextKeys property for the AjaxFileUpload control?
The code in the files no longer resembles these to be able to make these edits to the toolkit.
The markup that works by setting it statically is:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<ajaxToolkit:AjaxFileUpload ContextKeys="Testing" ID="ajaxFileUploadAttachments" runat="server" OnUploadComplete="ajaxFileUploadAttachments_UploadComplete" OnClientUploadStart="uploadStarted" />
</div>
</form>
and code behind:
protected void ajaxFileUploadAttachments_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
String ContextKeyValue = ajaxFileUploadAttachments.ContextKeys;
string fileNameWithPath = Server.MapPath("~/Temp/") + e.FileName.ToString();
ajaxFileUploadAttachments.SaveAs(fileNameWithPath);
}
In this version, the context key gets passed. If I try to set it from the code behind in the page load via:
protected void Page_Load(object sender, EventArgs e)
{
ajaxFileUploadAttachments.ContextKeys = "TestingFromPageLoad";
}
It doesn't work and I still get the static value of the control from the markup.
I have tried via an example in javascript using the OnClientUploadStart but still only the static value gets passed.
Anyone have a solution to this issue. I like the control but I need to be able to pass it a value without using session variables.
Thanks for any help and its greatly appreciated.