[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Button click -> add div with text boxes.

Posted on 2013-02-06
Medium Priority
Last Modified: 2013-03-07

I would like it so if a click my add button
    <asp:ImageButton id="addButton" src="images/add.PNG" OnClientClick="return false;"  class="addButton" runat="server" />

Open in new window

. It will show the below code
   <label class="alignme"  for="repdist1">Rep1 - </label>
     <label  for="repdist1">Distance:</label>
     <input  onkeypress="return IsNumber(event)" name="repdist1" type="text" id="repsit1" style="width:30px;" />
     <select name="kmormile1" id="kmormile1">
     	<option value="Miles">Miles</option>
        	<option value="Km">Km</option>
                       <label for="repmin1">Min:</label>
                     <input onkeypress="return IsNumber(event)" name="repmin1" type="text" value="00" maxlength="2" id="repmin1" style="width:30px;" />
                       <label for="repsec1">Sec:</label>
                     <input onkeypress="return IsNumber(event)" name="repsec1" type="text" value="00" maxlength="2" id="repsec1" style="width:30px;" />

Open in new window

each time a user clicks the button it adds a new row and if the user clicks the delete button
          <asp:ImageButton id="removeButton" class="removeButton" src="images/close_square.PNG" OnClientClick="return false;"   runat="server" />

Open in new window

it deletes a row.

I can do this in javascript but i would really like to do it in vb.net
Question by:runnerjp2005
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
  • 2
  • 2
LVL 83

Expert Comment

ID: 38858976
I wonder why you do not use a control like a GridView or a Repeater instead of adding/deleting rows of textboxes. In this case, you can use a repeater bound to a datatable and add/delete rows in datatable and repeater would automatically show new rows.

Author Comment

ID: 38858987
Its because its a form to fill in.
Basically its a training log and this has several fields.
I have a requirement where i have a rep field where a person could enter multiple reps e.g


so the button allows the user to enter more reps if need be.
LVL 23

Accepted Solution

Roopesh Reddy earned 2000 total points
ID: 38859039

Check the below code -
<div runat="server" id="container">

    <asp:Button ID="btnAdd" Text="Add Row" runat="server" OnClick="RowHandler" />
    <asp:Button ID="btnDelete" Text="Delete Row" runat="server" OnClick="RowHandler" />

Protected Sub RowHandler(sender As Object, e As EventArgs)
	Dim b As Button = TryCast(sender, Button)
	Dim lControls As New List(Of Control)()

	If b.ID = "btnAdd" Then
		If Session("controls") IsNot Nothing Then
			lControls = TryCast(Session("controls"), List(Of Control))
			For Each ctrl As Control In lControls

			Dim text As New TextBox()
			Session("controls") = lControls
			Dim text As New TextBox()
			Session("controls") = lControls
		End If
	End If
	'end:btnAdd if
	If b.ID = "btnDelete" Then
		If Session("controls") IsNot Nothing Then
			lControls = TryCast(Session("controls"), List(Of Control))

			If lControls.Count > 0 Then
				Dim ctrl As Control = TryCast(lControls(lControls.Count - 1), Control)
				Session("controls") = lControls

				For Each ctrls As Control In lControls

			End If

		End If
	End If
	'end:btnDelete if
End Sub

Open in new window

It's the sample code, to give you an idea to design it according to your need!

I basically wrote in C# and i converted it to VB. I think event handling is different in VB, but the logic inside the handler is same :)

Hope it helps u...

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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