How do I set my WorkflowGenFileUpload control as a required field?
Thursday, April 1, 2010 at 13:25 Issue
I cannot set my WorkflowGenFileUpload control to be a required field using FORM_FIELDS_REQUIRED action parameter.
Solution
WorkflowGenFileUpload control is not supported by the FORM_FIELDS_REQUIRED parameter. However, you can validate your WorkflowGenFileUpload by checking the .HasFile property before you call the SubmitToWorkflow() method.
You can also create a client side custom validation to check if a file has been uploaded to the WorkflowGenFileUpload control.
Example
Assuming you have a WorkflowGenFileUpload control with an ID “UPLOAD1”, add a .NET CustomValidator with ClientValidationFunction that validates UPLOAD1 (please see http://community.workflowgen.com/kb/how-can-i-use-a-net-customvalidator-control-in-my-workflowge.html for detail about CustomValidator).
C#
(in .aspx file)
Bind this javascript function to ClientValidationFunction of the CustomValidator
function ValidateWFGFileUpload(source, arguments)
{
var ValidateResult = true;
ValidateResult = CheckUPLOAD();
arguments.IsValid = ValidateResult;
}
(in .cs file)
Under Page_PreRender(), you add:
string WFGFileUploadStatus = UPLOAD1.HasFile.ToString().ToLower();
ClientScript.RegisterClientScriptBlock(typeof(string), "ValidateWFGFileUpload", "function CheckUPLOAD() {return " + WFGFileUploadStatus + "; }", true);
Whenever a user uploads a file through WorkflowGenFileUpload, the .HasFile property will be set to 'True'. You can use the above clientscript to define the validation result. If you have multiple WorkflowGenFileUpload controls to be validated, you can combine your FileUpload status and set it to the client side script return value.

Reader Comments