Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Jun 2015
    Location
    London
    Posts
    16
    Member #
    50439

    Pulling values for Dynamic form fields

    Could anyone help or point me in the right direction with pulling values from my dynamic form elements on my form?

    Darrick Wood School

    The above link is a test I have been working on, but when i click the submit button, its not pulling the values for the dynamic elements.

    I think what is happening, is the page is refreshing on postback, but its refreshing before the data is sent off to the database.

    Everything else on the form is pulled through fine, its just these dynamic elements that are the problem.

    I am using both JavaScript and visual basic.

    I have not posted all of the code behind as there was too much for this post.

    Code:
    Imports System.Data
    Imports System.Data.SqlClient
    
    Partial Class Application_Teaching
        Inherits System.Web.UI.Page
    
        Protected Sub Save(sender As Object, e As EventArgs) Handles SaveBTN.Click
            'This inserts the standard form components into the database
            Dim SPConn As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("con").ConnectionString
            Dim connection As New SqlConnection(SPConn)
    
            Dim SPCmd As SqlCommand
            Dim SPResource As String = "SP_NewApp"
            Dim OUTPUT As String = [String].Empty
    
            SPCmd = New SqlCommand(SPResource, connection)
    
            SPCmd.CommandType = Data.CommandType.StoredProcedure
    
            SPCmd.Parameters.Add(New SqlParameter("@postTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@postTXB").Value = postTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@titleDDL", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@titleDDL").Value = titleDDL.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@fnamesTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@fnamesTXB").Value = fnamesTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@snameTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@snameTXB").Value = snameTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@dobTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@dobTXB").Value = dobTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@ageTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@ageTXB").Value = ageTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@addressTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@addressTXB").Value = addressTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@hometelTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@hometelTXB").Value = hometelTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@worktelTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@worktelTXB").Value = worktelTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@mobnoTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@mobnoTXB").Value = mobnoTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@emailTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@emailTXB").Value = emailTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@niTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@niTXB").Value = niTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@wpdTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@wpdTXB").Value = wpdTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@QTIqtsdateTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@QTIqtsdateTXB").Value = QTIqtsdateTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@QTIdferefTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@QTIdferefTXB").Value = QTIdferefTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@QTInumeracyTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@QTInumeracyTXB").Value = QTInumeracyTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@QTIliteracyTXB", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@QTIliteracyTXB").Value = QTIliteracyTXB.Text
    
            SPCmd.Parameters.Add(New SqlParameter("@TB_details", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@TB_details").Value = TB_details.Value
    
            SPCmd.Parameters.Add(New SqlParameter("@TB_otherInt", Data.SqlDbType.NVarChar, 1000))
            SPCmd.Parameters("@TB_otherInt").Value = TB_otherInt.Value
    
            connection.Open()
            SPCmd.ExecuteNonQuery()
            connection.Close()
    
            'This gets the last AppID number to use for inserting in the ClonedFields table
            Dim DCcmd As SqlCommand = connection.CreateCommand()
            Dim SQLAppID As Data.SqlClient.SqlDataReader
            DCcmd.CommandText = "SELECT TOP 1 AppID FROM Applications ORDER BY DateCreated DESC"
            DCcmd.Connection.Open()
            SQLAppID = DCcmd.ExecuteReader()
            SQLAppID.Read()
            LB_AppID.Text = SQLAppID("AppID")
            DCcmd.Connection.Close()
    
            'Each ASP:Panel is listed below for the cloned sections. This iterates through each textbox and pulls out the values.
            For Each textBox As HtmlInputControl In TAPanel.Controls.OfType(Of HtmlInputControl)()
                Dim constr As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
                Using con As New SqlConnection(constr)
                    Using cmd As New SqlCommand("INSERT INTO dbo.ClonedFields (AppID,Text,TBID,DateCreated) VALUES(@AppID,@Text,@TBID,GETDATE())")
                        cmd.Connection = con
                        cmd.Parameters.AddWithValue("@AppID", LB_AppID.Text)
                        cmd.Parameters.AddWithValue("@Text", textBox.Value)
                        cmd.Parameters.AddWithValue("@TBID", textBox.ID)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                    End Using
                End Using
            Next
    
            For Each textBox As HtmlInputControl In EmpPanel.Controls.OfType(Of HtmlInputControl)()
                Dim constr As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
                Using con As New SqlConnection(constr)
                    Using cmd As New SqlCommand("INSERT INTO dbo.ClonedFields (AppID,Text,TBID,DateCreated) VALUES(@AppID,@Text,@TBID,GETDATE())")
                        cmd.Connection = con
                        cmd.Parameters.AddWithValue("@AppID", LB_AppID.Text)
                        cmd.Parameters.AddWithValue("@Text", textBox.Value)
                        cmd.Parameters.AddWithValue("@TBID", textBox.ID)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                    End Using
                End Using
            Next
    
            For Each textBox As HtmlInputControl In SchPanel.Controls.OfType(Of HtmlInputControl)()
                Dim constr As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
                Using con As New SqlConnection(constr)
                    Using cmd As New SqlCommand("INSERT INTO dbo.ClonedFields (AppID,Text,TBID,DateCreated) VALUES(@AppID,@Text,@TBID,GETDATE())")
                        cmd.Connection = con
                        cmd.Parameters.AddWithValue("@AppID", LB_AppID.Text)
                        cmd.Parameters.AddWithValue("@Text", textBox.Value)
                        cmd.Parameters.AddWithValue("@TBID", textBox.ID)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                    End Using
                End Using
            Next
    
            For Each textBox As HtmlInputControl In HighPanel.Controls.OfType(Of HtmlInputControl)()
                Dim constr As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
                Using con As New SqlConnection(constr)
                    Using cmd As New SqlCommand("INSERT INTO dbo.ClonedFields (AppID,Text,TBID,DateCreated) VALUES(@AppID,@Text,@TBID,GETDATE())")
                        cmd.Connection = con
                        cmd.Parameters.AddWithValue("@AppID", LB_AppID.Text)
                        cmd.Parameters.AddWithValue("@Text", textBox.Value)
                        cmd.Parameters.AddWithValue("@TBID", textBox.ID)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                    End Using
                End Using
            Next
    
            For Each textBox As HtmlInputControl In AddPanel.Controls.OfType(Of HtmlInputControl)()
                Dim constr As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
                Using con As New SqlConnection(constr)
                    Using cmd As New SqlCommand("INSERT INTO dbo.ClonedFields (AppID,Text,TBID,DateCreated) VALUES(@AppID,@Text,@TBID,GETDATE())")
                        cmd.Connection = con
                        cmd.Parameters.AddWithValue("@AppID", LB_AppID.Text)
                        cmd.Parameters.AddWithValue("@Text", textBox.Value)
                        cmd.Parameters.AddWithValue("@TBID", textBox.ID)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                    End Using
                End Using
            Next
    
        End Sub
    End Class
    Any help on this matter would be much appreciated.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,524
    Member #
    425
    Liked
    2787 times
    I'm guessing that by "dynamic form elements", you're referring to Teaching Appointments, Other Employment and Education.

    If I'm right, you may be looking for the ASP.net UpdatePanel. I'm not crazy about UpdatePanel as it tends to be somewhat bloated, but for this specific situation it might be what you need.

    ASP.NET AJAX > Overview > The UpdatePanel and UpdateProgress Controls > UpdatePanel Control Overview
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:35 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com