Im trying to create a webform that is a representation of a paper questionnaire that has 14 questions with yes/no answers. If an answer is no, then you must provide information as to why in 3 separate textboxes and store the information only when a user clicks no.

I also have 4 drop down lists that are chosen before the user answers the first question that also need to be stored with the textboxes, but the ddl's value does not change after the user starts. Right now I have 3 textboxes and a submit button for each of the 14 questions that are hidden until a user hits a "no" button, in which I change the visible property of all of them and the user then types in their reasons and submits the answer. I am currently doing this for each question and i hide/disable the textboxes and button after submitted.

My problem is that for each event on the 14 submit button's is that I'm forced to open & close an sql connection and insert the values. I know there has to be a way to simply this some so that I dont have 14 different groups of the same code. I would also like a way to eliminate having 40 textboxes on a page lol, because the idea was to have a pop up box or something open that would let the user submit it and then return to the question instead of hiding textboxes, but the user has to see all 14 questions at page load so if you got an answer to that one then that might solve my original question. After finishing a mock up of this I was utterly ashamed to look at my code and knew this couldnt be the only way but I just cant figure it out, any help would be appreciated!

Here is an example of something similar if you have a hard time understanding all that garbage.
Two separate questions, 2 separate answers. Please ignore errors, I am just trying to give a quick example.

Private Sub [B]btnQuestion_One[/B](ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuestion_One.Click
    
Command.CommandText = "INSERT into Customers Values @reason1, @reason2, @reason3, @cust_id" 

Command.Parameters.Add("@reason1", [B]textbox1.text[/B]) 
Command.Parameters.Add("@reason2", [B]textbox2.text[/B]) 
Command.Parameters.Add("@reason3", [B]textbox3.text[/B]) 
Command.Parameters.Add("@cust_id", ddlCustomer.SelectedItem)

Conn.Open
Command.ExecuteNonQuery
Conn.Close

textbox1.Visible = False
textbox2.Visible =False
textbox3.Visible =False
'etc.....

End Sub

Private Sub [B]btnQuestion_Two[/B](ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuestion_Two.Click

Command.CommandText = "INSERT into Customers Values @reason1, @reason2, @reason3, @cust_id" 

Command.Parameters.Add("@reason1", [B]textbox4.text[/B]) 
Command.Parameters.Add("@reason2", [B]textbox5.text[/B]) 
Command.Parameters.Add("@reason3", [B]textbox6.text[/B]) 
Command.Parameters.Add("@cust_id", ddlCustomer.SelectedItem)

CN.Open
Command.ExecuteNonQuery
CN.Close

textbox4.Visible = False
textbox5.Visible =False
textbox6.Visible =False
'etc.....

End Sub

I would also like a way to eliminate having 40 textboxes on a page lol, because the idea was to have a pop up box or something open that would let the user submit it and then return to the question instead of hiding textboxes

Hi,

You can try the inputbox for that.
To work with the InputBox, drag a Command Button and a TextBox from the Toolbar. Opon clicking the Command Button the InputBox prompts asks for a name. Once entered, press OK. That text will now be displayed in the Textbox.

The sample code for the click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles Button1.Click
Dim Show As String
Show = InputBox("Enter your name")
TextBox1.Text = Show
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.