Click to See Complete Forum and Search --> : Dynamic control validation problems


kal30
July 19th, 2005, 11:29 AM
I have a table with text boxes that i generate dynamically. I need to add some validation control to these text boxes.

Can anyone tell me where to put the validation code.

My code to generate the table is :

<code>

private sub create entry fields(num as integer)
Dim j As Integer
Dim no As Integer = CInt(noOfPermitee)
For j = 0 To num - 1
Dim tr As New TableRow
Dim td1 As New TableCell
Dim txt1 As New TextBox
txt1.TextMode = TextBoxMode.MultiLine
td1.Controls.Add(txt1)


Dim td2 As New TableCell
Dim txt2 As New TextBox
txt2.TextMode = TextBoxMode.MultiLine
td2.Controls.Add(txt2)
tblUserInputs.Rows.Add(tr)
Next
End sub

</code>

I call this sub in a button click event.

I am able to write the required field validator. I just don't know where to write the validation code.

My validation code is:

Dim reqval1 As New RequiredFieldValidator
reqval1.ControlToValidate = "txt1"
reqval1.ErrorMessage = "*"
reqval1.Text = "Please enter the agent name

Where should i put this code for the validation to fire.

Thank you

dmeikle
July 19th, 2005, 10:41 PM
you could do it in submit button's onclick event
<submit onclick="validateForm()" ...... />

i've also seen form tags have it:
<form method=post onsubmit="validateForm()">

aquafin
July 20th, 2005, 09:46 PM
I too have almost the same problem. I have a Radiobuttonlist in the datagrid. I need to validate the radiobuttonlist. So where do i write the validation code in this case.
I have place a Required field validator in the datagrid and set the controltovalidate property to the radiobuttonlist.This works, but if i want to write the validation code manually ,where do i place it?.