As a reference this is the control I am discussing here: AjaxControlToolKit AsyncFileUpload.
Context: maintenance on a legacy .NET webforms (codebehind) application. I am asked to show errors that occur serverside.
It is not possible to just set the label in the code behind, because the control performs an AsyncFileUpload.
As the API describes the control provides: OnClientUploadError
So I added that to the control:
<ajaxToolkit:AsyncFileUpload ID="fuImportEpAuth" runat="server"
OnClientUploadStarted="ImportEpAuthStartUpload"
OnClientUploadComplete="ImportEpAuthUploadComplete"
OnUploadedComplete="fuImportEpAuth_UploadedComplete"
OnClientUploadError="ImportEpAuthError" />
<asp:Label ID="lblImportWccAuth" runat="server" />
And added the following javascript to the page:
function ImportEpAuthError(sender, args) {
var errorText = args.get_errorMessage();
var errorLabel = document.getElementById('cphContent_lblImportWccAuth');
errorLabel.innerText = errorText;
errorLabel.style.color = "red";
$.unblockUI();
}
The code is performed and the label shows an errormessage.
Please focus on the: var errorText = args.get_errorMessage();
It contains this message:
Server Response Error: ' Object reference not set to an instance of an object.'
My problem or challenge is: It should show the errormessage I throw.
(This code is serverside)
try
{
// Upload and process file
UploadAndProcessFile(importType, fileUpload, sPath, settingsName);
}
catch (Exception ex)
{
//throw new Exception(ex.Message, ex);
throw new Exception("Please help me stackoverflow, I need to show this message!!!", ex);
}
If only I could fix this, then I could finish up and deliver the fix to production. I appreciate your help!