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
Solved

captcha control inside create user wizard.

Posted on 2009-07-07
13
1,328 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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