Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Problem with Validators

  Asked By: Mona    Date: Feb 02    Category: Asp.net    Views: 756
  

I am genetrating validators Dynamically but gettin an
err
Object reference not set to an instance of an
object.Can ne1 correct me.


For Cntr = 1 To CInt(noOfChoices)
Dim tr As New TableRow()
Dim tc As New TableCell()
Dim txt As New TextBox()

txt.ID = "Text" & CStr(Cntr)
txt.Text = Request("Text" &
CStr(Cntr))

Dim txtValid As
RequiredFieldValidator
txtValid.ControlToValidate =
txt.ID ***here Object reference not set to an
instance of an object
txtValid.ErrorMessage =
"Fields Cannot be Blank"
txtValid.Display =
ValidatorDisplay.Dynamic

tc.Text = " Choice" & Cntr & "
: "

tc.Font.Name = "Verdana"
tc.Font.Size = New
System.Web.UI.WebControls.FontUnit(10)

tr.Cells.Add(tc)

tc = New TableCell()
tc.Controls.Add(txt)
tr.Cells.Add(tc)

dynTable1.Rows.Add(tr)
Next

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Ellen Simpson     Answered On: Feb 02


Dim txtValid As RequiredFieldValidator

txtValid.id="r1"
r1.ControlToValidate =txt.ID

or some such. You must assign unique IDs to the validators you place on page and you most add thom to controls  collection or form.

 
Answer #2    Answered By: Patricia Johnson     Answered On: Feb 02


r1.ControlToValidate =txt.ID

This statment gives an err

 
Didn't find what you were looking for? Find more on Problem with Validators Or get search suggestion and latest updates.




Tagged: