views:

126

answers:

1

This is probably a lark, but for the recaptcha control as it sometimes takes a long time to render, is this possible?

If it takes more than say 5 seconds to render, I'd like to stop the rendering of the object and display my own captcha.

I'd start a timer on page load and if 5 seconds has elapsed, in some event in the recaptcha control (prerender?), I'd cancel the render or make it invisible or something to that effect. It is a 3rd party user control, so I don't have the source.

Update:

I tried the code below after I posted. It sort of works in that if the user control can't connect its server, ie - I turn disconnect my internet connection, but it doesn't sense when there is a really long pause when the control has waiting for the server to get back to it. Even if I change the millisecond interval to 1, the control renders.

<MTAThread()> _
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        Dim ucChk As New UCExistenceChecker(recaptcha, Me)
        Dim doFindUC As System.Threading.TimerCallback = AddressOf ucChk.FindUC
        Dim stateTimer As System.Threading.Timer = New System.Threading.Timer(doFindUC, Nothing, 0, 5000)
    End If

End Sub

Public Class UCExistenceChecker

    Dim _r As Recaptcha.RecaptchaControl
    Dim _pg As Page

    Sub New(ByVal r As Recaptcha.RecaptchaControl, ByVal pg As Page)
        _r = r
        _pg = pg
    End Sub

    Sub FindUC(ByVal stateInfo As Object)
        If _pg.FindControl("recaptcha") Is Nothing Then
            _r.SkipRecaptcha = True  'This "unrenders" the control, sort of.
        End If
    End Sub

End Class
+1  A: 

You may be able to use an iframe to contain the captcha block and subscribe to the either the readystatechanged or layoutcomplete events. You could then use setTimeout() to schedule some javscript to run after the maximum time you care to wait, and if neither of these events has fired, remove the iframe from the DOM and replace it with your own.

LBushkin
Thanks. I'll take a look at this. The weird thing with the recaptcha control is sometimes it takes 10 seconds to load and nothing is rendered on the screen. Not knowing what goes into the control, I guess it would be difficult to figure out how to stop the rendering before it gets to this phase.
Steve