2009-07-16 54 views
0

这可能是一个百灵,但对于recaptcha控制,因为它有时需要很长时间才能渲染,这可能吗?可能 - 如果未在x秒内加载,取消用户控件渲染?

如果渲染时间超过5秒,我想停止渲染对象并显示自己的验证码。

我会在页面加载时启动一个计时器,如果5秒过去了,在某些情况下,在recaptcha控件(prerender?)中,我会取消渲染或使其不可见或出现这种效果。这是第三方用户控件,所以我没有源代码。

更新:

我发布后试过下面的代码。它的工作原理在于,如果用户控件无法连接其服务器,即 - 我将断开与互联网的连接,但它不会检测到控件等待服务器返回时长时间停顿到它。即使我将毫秒间隔更改为1,控件也会呈现。

<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

您可能可以使用iframe来包含captcha块并订阅readystatechanged或layoutcomplete事件。然后,您可以使用setTimeout()安排一些JavaScript在您最关心的等待的最长时间之后运行,并且如果这两个事件均未触发,请从DOM中移除iframe并将其替换为您自己的。

+0

谢谢。我会看看这个。有关recaptcha控件的奇怪事情有时需要10秒才能加载,屏幕上不显示任何内容。不知道进入控制的内容是什么,我想很难弄清楚如何在渲染到达这个阶段之前停止渲染。 – Steve 2009-07-16 20:16:44