Help, Problem trying Validate Textboxes created at Run-Time

G

GOKU24

Framework: Version: 1.1
Language: VB.NET
Platform: Win 2K Pro

I need to validate dynamically created textboxes. The validation
controls are created at design time. The created Textbox is being
added to a Placeholder.

When I try to submit the page I get the following error:

Unable to find control id 'xxx' referenced by the 'ControlToValidate'
property of 'xxx'.


The textboxes are created on Page_Load. I've also tried creating them
on Page_Init, but I get the same error. A sample of the code is
below.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

EnableDisableTextboxes(strOne)

End If

End Sub

'Sub that creates Textbox at Run-Time
Public Sub EnableDisableTextboxes(ByVal strOne As String)

If X <= Y Then
Dim lblOne As New Label
lblOne.Text = strOne
plhOne.Controls.Add(lblOne)
Else
Dim txtOne As New TextBox
txtOne.TextMode = TextBoxMode.SingleLine
txtOne.Text = strOne
txtOne.ID = "txtOne"
plhOne.Controls.Add(txtOne)
regexOne.Visible = True
End If

End Sub

'Sample Validation code created at Design Time

<asp:regularexpressionvalidator id="regexOne" Runat="server"
ValidationExpression="XXXX" Display="None" ErrorMessage="Error
Message" Enabled="True" ControlToValidate="txtOne" Visible="False" />



Any help would be appreciated. Thanks in advance.


-T
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top