Adding a Compare Validator dynamically from code

R

RSH

I have a situation where I am generating webcontrols dynamically from
codebehind (1.1)

Everything is working properly except that I am also attempting to add a
Compare Validator which doesn't appear to be working, I get the error: "
Unable to find control id '67:::EX' referenced by the 'ControlToValidate'
property of ''.
which makes sense, but it begs the question can this be done??



cmdReader = New OleDbCommand(strSQL, cnReportDownloads)

dtrReader = cmdReader.ExecuteReader()

PlaceHolder1.Controls.Add(New LiteralControl("<table>"))

While dtrReader.Read

PlaceHolder1.Controls.Add(New LiteralControl("<tr><td>" &
dtrReader("FileName") & "</td><td>"))

Dim tb1 As New TextBox

tb1.ID = dtrReader("FileID") & ":::DL"

tb1.Width = Unit.Pixel(30)

tb1.Text = dtrReader("DownloadsLeft")

PlaceHolder1.Controls.Add(tb1)

PlaceHolder1.Controls.Add(New LiteralControl("</td><td>"))

Dim tb2 As New TextBox

tb2.ID = dtrReader("FileID") & ":::EX"

strSplit = Split(dtrReader("Expires"), " ")

tb2.Text = strSplit(0)

tb2.Width = Unit.Pixel(120)

PlaceHolder1.Controls.Add(tb2)

Dim vc As New CompareValidator

vc.ControlToValidate = tb2.ID

vc.Operator = ValidationCompareOperator.DataTypeCheck

vc.Type = ValidationDataType.Date

vc.ErrorMessage = "Please enter a valid date in the format: mm/dd/yyyy"

PlaceHolder1.Controls.Add(vc)

PlaceHolder1.Controls.Add(New LiteralControl("</td></tr>"))

End While

Dim bu As New Button

bu.ID = "Button2"

bu.Text = "Submit Changes"

PlaceHolder1.Controls.Add(New LiteralControl("<tr><td colspan='3'
align='center'><br><br>"))

PlaceHolder1.Controls.Add(bu)

PlaceHolder1.Controls.Add(New LiteralControl("</td></tr>"))

PlaceHolder1.Controls.Add(New LiteralControl("</table>"))





Thanks!

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top