2012-07-23 1 views
0

CreateUserWizard 내부에 Captcha 컨트롤을 통합하려고합니다.createuserwizard 내에서 Captcha 컨트롤 찾기

I got the Captcha control sample code from this website here

나는 경우를 사용하여 보안 문자를 기반으로 사용자의 입력에 대한 유효성 검사를하고 싶었다으로 .. 다른 .. 문. 그러나 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

텍스트 상자 txtCaptcha = (텍스트 상자) CreateUserWizardStep1.CreateUserStep.ContentTemplateContainer CreateUserWizard 내부 컨트롤을 찾으려면이 시도 여기

코드입니다 .FindControl ("txtCaptcha");