|Visual Studio version
||C# and VB.NET
all browsers supported by RadControls
Validating a RadCaptcha requires a postback to the server, because this validation can only be performed in the code-behind (which is the purpose of the RadCaptcha). In a normal case, however, a postback will remove the file the user has selected, as the upload control's client state will be cleared. This means that either validation must be performed in two steps where the first is validating, the second is the actual upload, or the user must select the file each time an invalid code is entered. Both of these cases are not desired by the end user, because they require extra effort.
There is a way to get around this by using the RadControls for ASP.NET AJAX - the RadAsyncUpload offers the functionality to persist its client state across postbacks and only upload the files in case a specific button is clicked. This is the PostbackTriggers property. More information about it is available in this help article
and this online demo
. The difficulty is using the same button for validating the RadCaptcha and uploading the file - if this file is configured as a postback trigger and an invalid code is entered the UploadedFiles collection will be lost, if it is not this collection will not be available. The solution for this is to store the old captcha text on the server (for example in the Session) and validate it manually in the PageInit event so you can modify the PostbackTriggers property accordingly - if the old value and the value the user posted match - set the postback trigger to the submit button so that we can later access the UploadedFiles, otherwise - keep it pointing to a hidden button whose purpose is to persist the client state. The file manipulation takes place in the button click event - a regular check for the captcha validation and a simple method to store the file.
The sample code with additional comments that explain each line is available in the attached file.
For convenience the same post exists in the RadCaptcha section here