This is a migrated thread and some comments may be shown as answers.
RadCaptcha does not show image
8 Answers 67 Views
This is a migrated thread and some comments may be shown as answers.
An
Top achievements
Rank 1
An asked on 02 Aug 2013, 02:02 PM
I am using Radcaptcha on my Login page and it is showing the image ok.  However, when I clicked on any button on my page, the image no longer appear.  I enabled the refresh linkbutton but this is not very user-friendly.  Is it possible that I programmatically refresh the image on OnLoad event so the image will be displayed every time?

Thanks for responding.

8 Answers, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 06 Aug 2013, 04:56 AM
Hello,

Please try the following


1) Set the “EnableRefreshImage” property of rad captcha to true

2) 
Hook the “OnClientLoad” event in javascript and a call the below javascript function
<script type="text/javascript">
       function GenerateNewImage() {
           var objradcaptcha = $find("<%=RadCaptcha1.ClientID %>");
           document.location = $get(objradcaptcha.get_id() + "_CaptchaLinkButton").href;
       }
   </script>


Thanks,
A2H
0
An
Top achievements
Rank 1
answered on 06 Aug 2013, 10:42 AM

I would get this error if call the javascript function.

Webpage error details

Message: 'null' is null or not an object
Line: 198
Char: 9
Code: 0
 
I have the radcaptcha and the javascript below in a separate .ascx file, loaded into the .aspx. 

Thanks.

0
A2H
Top achievements
Rank 1
answered on 06 Aug 2013, 01:06 PM

Hi,

I am afraid system will get the object of radcaptcha at runtime if you place the radcaptcha and javascript function in different pages.

Please add the javascript function in the same ascx page where RadCapthca exists.

Thanks,
A2H

0
An
Top achievements
Rank 1
answered on 06 Aug 2013, 01:11 PM
Sorry for the confusion.  I do put the javascript and the radcaptcha object in the same .ascx file.  This file is called by the .aspx page.  The null error occurs when I trigger GenerateNewImage(). 


 

<script type="text/javascript">
    function GenerateNewImage() {
        var objradcaptcha = $find("<%=RadCaptcha1.ClientID %>");
        document.location = $get(objradcaptcha.get_id() + "_CaptchaLinkButton").href;
    }

</script>

<div style="width: 400px;">
        <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Please enter the code below." EnableRefreshImage="true" RegisterWithScriptManager="true"
            ValidationGroup="Group" CaptchaTextBoxLabel="Type the code above" Font-Size="8pt">
        </telerik:RadCaptcha>
</div>


0
A2H
Top achievements
Rank 1
answered on 06 Aug 2013, 02:11 PM
Hello,
Please modify the javascript code like given below

<script type="text/javascript">
        function GenerateNewImage() {
            var $ = $telerik.$;
            var objradcaptcha = $find("<%=RadCaptcha1.ClientID %>");
            document.location = $get(objradcaptcha.get_id() + "_CaptchaLinkButton").href;
        }
    </script>


Thanks,
A2H
0
An
Top achievements
Rank 1
answered on 14 Aug 2013, 12:59 PM
A2H,

I still got a Javascript error when trying to activate the link button automatically.  The clientID returned is still null, therefore, gave an exception on the browser.

Thanks.
0
Slav
Telerik team
answered on 16 Aug 2013, 03:28 PM
Hi An,

It is possible that the client-side object of the RadCaptcha is still not initialized when you invoke GenerateNewImage. Please verify that you are calling the function on the client-side event OnClientLoad of the captcha, on Sys.Application.load or after these events.

Nevertheless, this is a workaround that may not remove the problem entirely. Please clarify whether a gray image appears or there is no image at all when the problem occurs.
 - If the image is grey, please check this help article on the matter.
 - In case the image just disappears, please provide a more detailed description of your setup and the steps for recreating the problem so that I can inspect it locally.

Regards,
Slav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
An
Top achievements
Rank 1
answered on 16 Aug 2013, 04:34 PM

Hi Slav,

 

Yes, call the function with OnClientLoad  works llike a charm.  The usually grayed out image is now automatically refreshed.

 

Thank you.

An

Asked by
An
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
An
Top achievements
Rank 1
Slav
Telerik team
Share this question
or