ASP.net:"未将对象引用设置到对象的实例"对于现有对象 [英] ASP.net: "Object reference not set to an instance of an object." for an existing object

查看:90
本文介绍了ASP.net:"未将对象引用设置到对象的实例"对于现有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 MSCaptcha asp.net 4.0 Web应用程序的控制。我已经放在提供的 .DLL 的.xml 文件夹中的文件,并添加<%@注册大会=MSCaptcha命名空间=MSCaptcha标签preFIX =CC1%>在页面顶部
这是我如何使用它的页面:

I'm using MSCaptcha control in asp.net 4.0 web application. I've placed provided .dll and .xml files in the Bin folder and added <%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %> in top of page. It's how I use it in page:

<cc1:CaptchaControl ID="Captcha1" runat="server"
                 CaptchaBackgroundNoise="Low" CaptchaLength="4"
                 CaptchaHeight="60" CaptchaWidth="300"
                 CaptchaLineNoise="None" CaptchaMinTimeout="1"
                 CaptchaMaxTimeout="240" FontColor = "#529E00" />

和在code后面我用这样的:

And in code behind I use it like this:

If Page.FindControl("Captcha1").ToString = "MSCaptcha.CaptchaControl" Then
    Captcha1.ValidateCaptcha(webCaptcha.Text.Trim())

    If Captcha1.UserValidated Then
        addComment()
    Else
        webWrongCaptcha.Text = "Captcha is wrong!"
    End If
Else
    Response.Redirect("contact.aspx?c=e")
End If

但是,如果用户点击后按钮,我面对这个错误 CaptchaMaxTimeout

Line 7:              Captcha1.ValidateCaptcha(webCaptcha.Text.Trim())

我怎样才能解决这个问题?

How can I fix it?

推荐答案

包裹你的逻辑在确定的验证码为空声明,在调用它的属性。如果是,则通过发送消息到客户端,让他们知道他们超过超时而他们需要再次尝试处理错误。

Wrap your logic in a statement that determines if the Captcha is null, prior to calling it's properties. If it is, handle the error by sending a message to the client letting them known they exceeded the timeout and they need try again.

这篇关于ASP.net:&QUOT;未将对象引用设置到对象的实例&QUOT;对于现有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆