Dynamic Controls [xx(]
Hello Folks,
I am adding 4 labels,4 textboxs,4 combos to form dynamically at runtime to a panel.These are added according to selected value in the combobox.But now i want to validate each textbox which added dynamically on the panel.I am unable to identify each textbox.Can u please help me.Here i am giving my sample code.
Panel1.Visible = True
Panel1.Controls.Clear()
Dim ch As String = cmbchoices.SelectedItem.ToString
Dim i As Integer
Dim lblsno As Label
Dim txtanswer As TextBox
Dim cmbrw As ComboBox
Dim pos As Integer = 20
Label4.Visible = True
Label5.Visible = True
Panel1.Controls.Add(Label4)
Panel1.Controls.Add(Label5)
Label4.Location = New Point(50, 5)
Label5.Location = New Point(265, 5)
For i = 1 To CType(ch, Integer)
lblsno = New Label()
lblsno.Name = "lbl" & i
'lblsno.ForeColor = White
lblsno.Location = New Point(30, 10 + pos)
lblsno.Size = New Size(20, 23)
lblsno.Text = i.ToString
Panel1.Controls.Add(lblsno)
txtanswer = New TextBox()
txtanswer.Name = "txt" & i
txtanswer.Location = New Point(50, 10 + pos)
txtanswer.Size = New Size(200, 23)
Panel1.Controls.Add(txtanswer)
cmbrw = New ComboBox()
cmbrw.Name = "cmb" & i
cmbrw.Location = New Point(270, 10 + pos)
cmbrw.Size = New Size(100, 23)
cmbrw.Items.Add("Right")
cmbrw.Items.Add("Wrong")
cmbrw.SelectedIndex = 1
Panel1.Controls.Add(cmbrw)
pos = pos + 30
If txtanswer.Text = "" Then
ErrorProvider1.SetError(txtanswer, "You Must Enter")
Else
ErrorProvider1.BlinkStyle = ErrorBlinkStyle.NeverBlink
End If
Next
Insert.Visible = True
End If
|