2012-07-23 52 views
0

我正在将一个Captcha控件集成到CreateUserWizard中。在createuserwizard中查找Captcha控件

I got the Captcha control sample code from this website here

正如我想做的事,如果使用基于该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

尝试此找到的CreateUserWizard内部的控制

文本框txtCaptcha =(文本框)CreateUserWizardStep1.CreateUserStep.ContentTemplateContainer .FindControl( “txtCaptcha”);