Solved

captcha control inside create user wizard.

Posted on 2009-07-07
13
1,313 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now