可能 - 如果在 x 秒内未加载,则取消用户控件渲染?

发布于 2024-07-26 23:27:20 字数 1189 浏览 5 评论 0原文

这可能是一种乐趣,但是对于验证码控件来说,因为它有时需要很长时间才能渲染,这可能吗?

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

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

更新:

我在发布后尝试了下面的代码。 它的工作原理是,如果用户控件无法连接其服务器,即 - 我断开互联网连接,但当控件等待服务器返回时,当有很长的暂停时,它不会感觉到到它。 即使我将毫秒间隔更改为 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏夜暖风 2024-08-02 23:27:20

您可以使用 iframe 来包含验证码块并订阅 ReadyStateChanged 或LayoutComplete 事件。 然后,您可以使用 setTimeout() 安排一些 JavaScript 在您希望等待的最长时间之后运行,如果这些事件都没有触发,则从 DOM 中删除 iframe 并用您自己的 iframe 替换它。

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 JavaScript 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文