HI Gurus. I am trying to generate a Table with dynamic controls in different
cells. I am at the same time generating Validation controls and assigning
"control to validate" property to the ID of the generated controls. The
generation works as expected, however when I press the submit button,
validation controls do not react. I posted the code below for the entire
table. In the last line I add the table to a session and regenerate the table
in the Page_Init between postbacks. Can anyone suggest why the validation
does not fire? BTW the "Causesvalidation" property of the submit button is
"ON". In advance, many thanks.
For counter = 0 To CInt(qty - 1)
tRow = New HtmlTableRow
tRow.ID = "fltRow" & counter
'mile cells
tCell = New HtmlTableCell
tCell.ID = "cellMile" & counter
tCell.Width = "20px"
txbMile = New TextBox
txbMile.ID = "txbMile" & counter
validator = New RangeValidator
validator.ControlToValidate = "txbMile" & counter
validator.Type = ValidationDataType.Integer
validator.MinimumValue = txbStartMile.Text
validator.MaximumValue = txbEndMile.Text
validator.Text = "*"
validator.ErrorMessage = "The value must be between " &
txbStartMile.Text & " and " & txbEndMile.Text
txbMile.Width = New System.Web.UI.WebControls.Unit(30)
tCell.Controls.Add(txbMile)
tCell.Controls.Add(validator)
tRow.Cells.Add(tCell)
'chain Cells
tCell = New HtmlTableCell
tCell.ID = "cellChan" & counter
tCell.Width = "20px"
txbchain = New TextBox
validator = New RangeValidator
validator.Type = ValidationDataType.Integer
validator.ControlToValidate = "cellChan" & counter
validator.MinimumValue = txbStartYards.Text
validator.MaximumValue = txbEndYards.Text
validator.Text = "*"
validator.ErrorMessage = "The value must be between " &
txbStartYards.Text & " and " & txbEndYards.Text
txbchain.Width = New System.Web.UI.WebControls.Unit(30)
txbchain.ID = "txbChain" & counter
tCell.Controls.Add(txbchain)
tRow.Cells.Add(tCell)
'fault Cells
tCell = New HtmlTableCell
tCell.ID = "cellFault" & counter
tCell.Width = "80%"
' validator = New RangeValidator
txbFault = New TextBox
txbFault.ID = "txbFault" & counter
recValidator = New RequiredFieldValidator
recValidator.ControlToValidate = "txbFault" & counter
recValidator.Text = "*"
recValidator.ErrorMessage = "Please add the fault"
txbFault.Wrap = True
txbFault.TextMode = TextBoxMode.MultiLine
txbFault.Width = New System.Web.UI.WebControls.Unit(400)
tCell.Controls.Add(txbFault)
tRow.Cells.Add(tCell)
'add created row to the table
tableFaults.Rows.Add(tRow)
Next
tableFaults.Width = "100%"
tableFaults.Border = "1"
tableFaults.ID = "tblFaults"
pnlFaults.Controls.Add(tableFaults)
Session("tableFaults") = tableFaults