Private Property QuantityDinamicControls() As Integer
Get
If ViewState("Quantity") = Nothing Then
ViewState("Quantity") = 0
End If
Return DirectCast(ViewState("Quantity"), Integer)
End Get
Set(ByVal value As Integer)
ViewState("Quantity") = value
End Set
End Property
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Me.QuantityDinamicControls += 1
Me.validacionHojaVisas.Text = ViewState("Quantity")
End Sub
Protected Overloads Overrides Sub CreateChildControls()
If Page.IsPostBack Then GenerateControls()
End Sub
Private Sub GenerateControls()
Dim Quantity As Integer = 0
While Quantity <= Me.QuantityDinamicControls
Dim concepto As New
Dim txt1, txt2, txt3, txt4 As New TextBox()
Dim descripcion, facturable, orden, proyecto, importe As New Label()
descripcion.Attributes.Add("style", "margin-bottom: 10px")
descripcion.ID = "descricion" + (Quantity + 1).ToString()
descripcion.Text = "Descripción:"
txt1.Attributes.Add("style", "margin-bottom: 10px")
txt1.ID = "txt1" + (Quantity + 1).ToString()
txt1.Text = "Descripción..."
facturable.Attributes.Add("style", "margin-bottom: 10px")
facturable.ID = "facturable" + (Quantity + 1).ToString()
facturable.Text = "Facturable:"
orden.Attributes.Add("style", "margin-bottom: 10px")
orden.ID = "orden" + (Quantity + 1).ToString()
orden.Text = "Orden:"
txt2.Attributes.Add("style", "margin-bottom: 10px")
txt2.ID = "txt2" + (Quantity + 1).ToString()
txt2.Text = "Orden..."
proyecto.Attributes.Add("style", "margin-bottom: 10px")
proyecto.ID = "proyecto" + (Quantity + 1).ToString()
proyecto.Text = "Proyecto:"
txt3.Attributes.Add("style", "margin-bottom: 10px")
txt3.ID = "txt3" + (Quantity + 1).ToString()
txt3.Text = "Proyecto..."
importe.Attributes.Add("style", "margin-bottom: 10px")
importe.ID = "importe" + (Quantity + 1).ToString()
importe.Text = "Importe:"
txt4.Attributes.Add("style", "margin-bottom: 5px")
txt4.ID = "txt4" + (Quantity + 1).ToString()
txt4.Text = "Importe..."
phDinamicControls.Controls.Add(descripcion)
phDinamicControls.Controls.Add(txt1)
phDinamicControls.Controls.Add(facturable)
phDinamicControls.Controls.Add(orden)
phDinamicControls.Controls.Add(txt2)
phDinamicControls.Controls.Add(proyecto)
phDinamicControls.Controls.Add(txt3)
phDinamicControls.Controls.Add(importe)
phDinamicControls.Controls.Add(txt4)
phDinamicControls.Controls.Add(New LiteralControl("<br/>"))
Quantity += 1
End While
End Sub
Private Function GetTxtControls() As String
Dim sb As New StringBuilder
Dim i As Integer = 0
While i <= Me.QuantityDinamicControls
Dim descripcion As String = "descripcion" + (i + 1).ToString()
Dim facturable As String = "facturable" + (i + 1).ToString()
Dim orden As String = "orden" + (i + 1).ToString()
Dim proyecto As String = "proyecto" + (i + 1).ToString()
Dim importe As String = "importe" + (i + 1).ToString()
Dim txt1 As String = "txt1" + (i + 1).ToString()
Dim txt2 As String = "txt2" + (i + 1).ToString()
Dim txt3 As String = "txt3" + (i + 1).ToString()
Dim txt4 As String = "txt4" + (i + 1).ToString()
Dim descripcionControl As TextBox = TryCast(phDinamicControls.FindControl(descripcion), TextBox)
Dim facturableControl As TextBox = TryCast(phDinamicControls.FindControl(facturable), TextBox)
Dim ordenControl As TextBox = TryCast(phDinamicControls.FindControl(orden), TextBox)
Dim proyectoControl As TextBox = TryCast(phDinamicControls.FindControl(proyecto), TextBox)
Dim importeControl As TextBox = TryCast(phDinamicControls.FindControl(importe), TextBox)
Dim txtControl1 As TextBox = TryCast(phDinamicControls.FindControl(txt1), TextBox)
Dim txtControl2 As TextBox = TryCast(phDinamicControls.FindControl(txt2), TextBox)
Dim txtControl3 As TextBox = TryCast(phDinamicControls.FindControl(txt3), TextBox)
Dim txtControl4 As TextBox = TryCast(phDinamicControls.FindControl(txt4), TextBox)
sb.Append(descripcionControl.Text & "<br />")
sb.Append(facturableControl.Text & "<br />")
sb.Append(ordenControl.Text & "<br />")
sb.Append(proyectoControl.Text & "<br />")
sb.Append(importeControl.Text & "<br />")
sb.Append(txtControl1.Text & "<br />")
sb.Append(txtControl2.Text & "<br />")
sb.Append(txtControl3.Text & "<br />")
sb.Append(txtControl4.Text & "<br />")
i += 1
End While
Return sb.ToString
End Function