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 DropDownList()
Dim facturableList As New RadioButtonList()
Dim txt1, txt2, txt3, txt4 As New TextBox()
Dim descripcion, facturable, orden, proyecto, importe, validacionFacturable, validacionOrden, validacionProyecto, validacionImporte As New Label()
concepto.Attributes.Add("style", "margin-bottom: 10px")
concepto.ID = "concepto" + (Quantity + 1).ToString()
concepto.SelectedIndex = ViewState("concepto_index")
'AddHandler concepto.SelectedIndexChanged, AddressOf concepto_SelectedIndexChanged
'concepto.AutoPostBack = True
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..."
txt1.BackColor = Drawing.Color.Silver
txt1.Width = 250
facturable.Attributes.Add("style", "margin-bottom: 10px")
facturable.ID = "facturable" + (Quantity + 1).ToString()
facturable.Text = "Facturable:"
facturableList.Attributes.Add("style", "margin-bottom: 10px")
facturableList.ID = "facturableList" + (Quantity + 1).ToString()
facturableList.Items.Add("SI")
facturableList.Items.Add("NO")
facturableList.Enabled = False
facturableList.RepeatDirection = RepeatDirection.Horizontal
facturableList.RepeatLayout = RepeatLayout.Flow
validacionFacturable.Attributes.Add("style", "margin-bottom: 10px")
validacionFacturable.ID = "validacionFacturable" + (Quantity + 1).ToString()
validacionFacturable.Text = ""
validacionFacturable.ForeColor = Drawing.Color.Red
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..."
txt2.BackColor = Drawing.Color.Silver
txt2.Width = 90
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..."
'txt4.AutoPostBack = True
txt4.BackColor = Drawing.Color.Silver
txt4.Width = 50
AddHandler txt4.TextChanged, AddressOf Me.txt4_TextChanged
validacionImporte.Attributes.Add("style", "margin-bottom: 10px")
validacionImporte.ID = "validacionImporte" + (Quantity + 1).ToString()
validacionImporte.Text = ""
validacionImporte.ForeColor = Drawing.Color.Red
phDinamicControls.Controls.Add(concepto)
phDinamicControls.Controls.Add(New LiteralControl(" "))
cargarComboBoxConceptos(concepto)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(descripcion)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(txt1)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(facturable)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(facturableList)
phDinamicControls.Controls.Add(validacionFacturable)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(importe)
phDinamicControls.Controls.Add(New LiteralControl(" "))
phDinamicControls.Controls.Add(txt4)
phDinamicControls.Controls.Add(validacionImporte)
phDinamicControls.Controls.Add(New LiteralControl("<br/>"))
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 concepto As String = "concepto" + (i + 1).ToString()
Dim validacionFacturable As String = "validacionFacturable" + (i + 1).ToString()
Dim validacionImporte As String = "validacionImporte" + (i + 1).ToString()
Dim facturableList As String = "facturableList" + (i + 1).ToString()
Dim descripcion As String = "descripcion" + (i + 1).ToString()
Dim facturable As String = "facturable" + (i + 1).ToString()
Dim importe As String = "importe" + (i + 1).ToString()
Dim txt1 As String = "txt1" + (i + 1).ToString()
Dim txt4 As String = "txt4" + (i + 1).ToString()
Dim facturableListControl As RadioButtonList = TryCast(phDinamicControls.FindControl(facturableList), RadioButtonList)
Dim conceptoControl As DropDownList = TryCast(phDinamicControls.FindControl(concepto), DropDownList)
Dim validacionFacturableControl As Label = TryCast(phDinamicControls.FindControl(validacionFacturable), Label)
Dim validacionImporteControl As Label = TryCast(phDinamicControls.FindControl(validacionImporte), Label)
Dim descripcionControl As Label = TryCast(phDinamicControls.FindControl(descripcion), Label)
Dim facturableControl As Label = TryCast(phDinamicControls.FindControl(facturable), Label)
Dim importeControl As Label = TryCast(phDinamicControls.FindControl(importe), Label)
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(validacionFacturableControl.Text & "<br />")
sb.Append(validacionImporteControl.Text & "<br />")
sb.Append(facturableListControl.Text & "<br />")
sb.Append(conceptoControl.Text & "<br />")
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