Solved

captcha control inside create user wizard.

Posted on 2009-07-07
13
1,338 Views
Last Modified: 2012-06-27
My captcha control works great outside of the create user wizard.

But when I add it inside the wizard I cannot seem to find the control, comes back with null error.

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
        'Dim CaptchaControl1 As MSCaptcha.CaptchaControl = DirectCast(CreateUserWizard1.FindControl("CaptchaControl1"), MSCaptcha.CaptchaControl)
        ' Response.Write(loginCAPTCHA)
        'Dim address1 As TextBox
        Dim newBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCap"), TextBox)
        Dim loginCAPTCHA As MSCaptcha.CaptchaControl = DirectCast(CreateUserWizard1.FindControl("CaptchaControl1"), MSCaptcha.CaptchaControl)
 
 
        loginCAPTCHA.ValidateCaptcha(Me.txtCap.Text)
        If loginCAPTCHA.UserValidated Then
            Response.Write("wrong try again")
            Return
 
        Else 
 
 
''''' asp.net
  <asp:TextBox ID="txtCap" runat="server"  ></asp:TextBox></div>
   <cc1:captchacontrol id="CaptchaControl1"   CustomValidatorErrorMessage="*Please retry to confirm you are human." runat="server" FontColor="80, 35, 114" 
        CaptchaFontWarping="Medium" CaptchaBackgroundNoise="Medium"></cc1:captchacontrol>

Open in new window

0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24798091
Did you try finding it the way like you are finding the TextBox txtCap i.e. finding inside ContentTemplateContainer:

Dim newBox As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCap"), TextBox)

i.e.

        Dim loginCAPTCHA As MSCaptcha.CaptchaControl = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("CaptchaControl1"), MSCaptcha.CaptchaControl)
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24798257
Yes, I even tried a response.write to see if it shows up, Nothing.  You got anything else
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24798584
which line is throwing exception?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:sevensnake77
ID: 24799150
well its not just that its any text box i add. Lets make it simple like this one.

Dim txtfname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtfname"), TextBox)
Protected WithEvents txtfname As Global.System.Web.UI.WebControls.TextBox
 
 

cmdInsert.Parameters.Add(New SqlParameter("@fname", Data.SqlDbType.VarChar, 500))
cmdInsert.Parameters("@fname").Value = Me.txtfname.Text
 
No matter what I get a null reference
 
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24803593
Ok I read something about add a tb i guess to find the id. Can you help with this.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24804267
can you post your CUW code here ...to get some more idea on what exactly is going on since you are not even able to find a normal textbox..
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24804880
LOL I know right. Ok. Finding it in the createuserwizard is more different than just finding it by itself or in a datagrid.
I really appreciate this.

 <asp:CreateUserWizard ID="CreateUserWizard1"            
                 runat="server"  
        CreateUserButtonText="Submit">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
                <ContentTemplate>
                <table><tr><td align="left">
<div align="left">
<table border="0">
<tbody align="left">
<tr>
<td align="left" colspan="2">
<asp:Label ID=top runat=server Text="Sign Up for Your New Account" Font-Bold="True" Font-Size="10pt"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="Label1" runat="server" >First Name:</asp:Label></td>
<td align=left>
<asp:TextBox ID="fname" runat="server"></asp:TextBox>
</td>
</tr>
</table>
 
</ContentTemplate>
            </asp:CreateUserWizardStep>
          <%--  <asp:CompleteWizardStep ID="CompleteWizardStep2" runat="server">
            <ContentTemplate>      
           
            </ContentTemplate>
            </asp:CompleteWizardStep>--%>
        </WizardSteps>
    </asp:CreateUserWizard>  


Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
        ' Get the UserId of the just-added user
        Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
 
        If Not user Is Nothing Then
            Dim userId As New Guid(user.ProviderUserKey.ToString())
 
            Dim fname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.FindControl("fname"), TextBox)
            Dim lname As TextBox = CType(CreateUserWizard1.FindControl("lname"), TextBox)
            Dim address1 As TextBox = CType(CreateUserWizard1.FindControl("address1"), TextBox)

Open in new window

0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 24805113
Try using the code below exactly it is...i.e. copy+paste

 Dim fname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("fname"), TextBox)
Dim str As String = fname.Text

One more question...is your CUW control inside some other control(e.g. LoginView control ) or MasterPage
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24805701
The create user wizard is a login control in itself. But allows you to change the template format to a more editable control. This is what allows me to add more text boxes.  Ok i will. give me about 2 hours have a MT thanks.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24806001
Yes...I understand CUW is a login Control....but there is another control called LoginView control.
So I understand that CUW is not inside any other control.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24808981
System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Open in new window

Line 88: System.NullReferenceException: Object reference not set to an instance of an  object.

Source Error: 

    Line 88: 
Line 89:         Dim fname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("fname"), TextBox)
Line 90:         Dim str As String = fname.Text


Line 89:         Dim fname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("fname"), TextBox)
Line 90:         Dim str As String = fname.Text

Open in new window

0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24809181
not sure whats going on.....some small messed up thing...
do you mind trying with a new CUW control..
By the way what is line 88 in your code?
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24809817
I got it using this and it works now, Thanks.
Dim fname As TextBox = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtfname"), TextBox)
cmdInsert.Parameters.Add(New SqlParameter("@fname", Data.SqlDbType.VarChar, 500))

        cmdInsert.Parameters("@fname").Value = fname.Text

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question