tags:

views:

567

answers:

1

I have a wizard control in wich I am adding a user control containing a simple table with some input fields based on users entry of how many children they have. ex: how many kids do you have so I add the user control ascx based on that loop that goes into step 5 of my wizard wich is also in a masterpage.

I then use findcontrol to atttempt the get to those input boxes so i can save the data into my db, findcontrol allway comes up null, even though the user control in visable and recreated on page load after post back.

any help greatly appreciated. find control button: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim numbchildren As Integer = CInt(Howmanychildren.Text)

    For i As Integer = 1 To numbchildren - 1

        Dim textbox As TextBox = TryCast(Me.Wizard1.FindControl("WizardStep5").FindControl("Minor_1_Child_Name"), TextBox)
        'Dim textbox2 As TextBox = TryCast(Me.Wizard1.FindControl("WizardStep5").FindControl("Howmanychildren"), TextBox)


        If textbox IsNot Nothing Then

            Response.Write("Found TextBox1 <br>")
            Dim val As String = textbox.Text
            Response.Write(val & "<br>")

        Else
            Response.Write("not found" & "<br>")
        End If

        ' Insert into DB
        'SaveValueToDatabase(val)
    Next

End Sub

user control added function on dropdown :

Protected Sub Doyouhavechildren_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Doyouhavechildren.SelectedIndexChanged

    Dim numbchildren As Integer = CInt(Howmanychildren.Text)
    Dim cnt As Integer = 1


    'Panel1.Controls.Clear()

    Select Case Doyouhavechildren.SelectedIndex
        Case 0



            ViewState.Add("Doyouhavechildren", numbchildren)


            Do While cnt <= numbchildren

                Dim uc As Web.UI.UserControl = DirectCast(Page.LoadControl("MinorChild.ascx"), Web.UI.UserControl)
                uc.ID = "Minor_" + cnt.ToString()
                Wizard1.ActiveStep.Controls.Add(uc)



                cnt = cnt + 1 
            Loop
            Exit Select
        Case 1

            Exit Select
    End Select

End Sub

user control:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MinorChild.ascx.vb" Inherits="MinorChild" %>

Name

Age

SS#

DOB

the find control works in the howmanychildren field that is static

A: 

I figured it out myself basicly, you have to referance the container, thats what everyone everywhere else where saying but I kept ignoring the answer the correct code is

Dim textbox As TextBox = TryCast(Me.Wizard1.FindControl("WizardStep5").FindControl("Minor_1").FindControl("Child_Name"), TextBox)

you have to referance the user control name first then search within it , even though the client source is disceptive.