在createuserwizard中查找Captcha控件

时间:2012-07-23 08:22:11

标签: c# asp.net captcha createuserwizard

我在CreateUserWizard中集成了一个Captcha控件。

I got the Captcha control sample code from this website here

因为我想使用if .. else ..语句基于Captcha对用户输入进行验证。 但是,当我尝试从createuserwizard获取Captcha控件时发生错误。

这是错误:

The name 'Captcha1' does not exist in the current context

我曾尝试将此控件作为文本框,图像,控件但不成功。

以下是代码:

 <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
              <ContentTemplate>

 <tr>
                            <td class="style4">Answer:</td>
                            <td>
                                <cc1:CaptchaControl ID="Captcha1" runat="server"
                                 CaptchaBackgroundNoise="Medium" CaptchaLength="5"
                                 CaptchaHeight="55" CaptchaWidth="200"
                                 CaptchaLineNoise="None" CaptchaMinTimeout="5"
                                 CaptchaMaxTimeout="240" FontColor = "#FF33CC" CaptchaFontWarping="Medium" />

                                 <asp:TextBox runat="server" ID="txtCaptcha" />

                            </td>
                        </tr>
 </ContentTemplate>

              </asp:CreateUserWizardStep>

代码背后:

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        //Control Captcha1 = (Control)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captcha1");
        TextBox txtCaptcha = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCaptcha");

            Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());//error occurred here

        if (Captcha1.UserValidated)//error occurred here
        {

     }

} 

1 个答案:

答案 0 :(得分:1)

尝试此操作以查找CreateUserWizard中的控件

TextBox txtCaptcha =(TextBox)CreateUserWizardStep1.CreateUserStep.ContentTemplateContainer.FindControl(“txtCaptcha”);