471,570 Members | 988 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Help!! Dynamic Textbox, validation requiredFieldValidator

Hello !!

I am creating a dynamic textbox and want to validate it using the
requiredfieldvalidator.

These are the steps which I tried:
================================================== ==
1) In Page_load,

Dim Email As New Label
Email.Text = "* Email Address"
placeHolder1.Controls.Add(Email)

Dim txtEmailAddress As New TextBox
placeHolder2.Controls.Add(txtEmailAddress )
2) The HTML has:
<tr><td>
<asp:PlaceHolder ID="placeHolder1" Runat="server"></asp:PlaceHolder>
<asp:requiredfieldvalidator id="reqFieldVal1" runat="server"
Display="Dynamic" ErrorMessage="Required"
ControlToValidate="txtEmailAddress"></asp:requiredfieldvalidator>
</td>
</tr>

================================================== ==

This gives an error message :

Unable to find control id 'txtEmailAddress' referenced by the
'ControlToValidate' property of 'reqFieldVal1'.
I tried the following options, but was unsuccessful:

a) Move requiredFieldValidator inside placeholder. (Googling around,
suggested that the validator and control should be in the same
container)

b) Tried to create requiredFieldValidator dynamically and add it in the
same placeholder (ie placeHolder1)

Any pointers will be appreciated !!

TIA..

Nov 13 '06 #1
2 6351
RSH
Christina,

You have to set the ID property of the textbox. You are creating a textbox
object and then referring to it in code but from the perspective of the form
it has no ID so .Net is making and ID up which doesn't align with the name
you have given it.

Dim txtEmailAddress As New TextBox

txtEmailAddress.ID = "txtEmailAddress" <---- Add this

PlaceHolder2.Controls.Add(txtEmailAddress)

Dim ReqFieldVal As New RequiredFieldValidator

ReqFieldVal.ControlToValidate = "txtEmailAddress"

ReqFieldVal.ErrorMessage = "Required"

PlaceHolder2.Controls.Add(ReqFieldVal)

HTH,

Ron

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hello !!

I am creating a dynamic textbox and want to validate it using the
requiredfieldvalidator.

These are the steps which I tried:
================================================== ==
1) In Page_load,

Dim Email As New Label
Email.Text = "* Email Address"
placeHolder1.Controls.Add(Email)

Dim txtEmailAddress As New TextBox
placeHolder2.Controls.Add(txtEmailAddress )
2) The HTML has:
<tr><td>
<asp:PlaceHolder ID="placeHolder1" Runat="server"></asp:PlaceHolder>
<asp:requiredfieldvalidator id="reqFieldVal1" runat="server"
Display="Dynamic" ErrorMessage="Required"
ControlToValidate="txtEmailAddress"></asp:requiredfieldvalidator>
</td>
</tr>

================================================== ==

This gives an error message :

Unable to find control id 'txtEmailAddress' referenced by the
'ControlToValidate' property of 'reqFieldVal1'.
I tried the following options, but was unsuccessful:

a) Move requiredFieldValidator inside placeholder. (Googling around,
suggested that the validator and control should be in the same
container)

b) Tried to create requiredFieldValidator dynamically and add it in the
same placeholder (ie placeHolder1)

Any pointers will be appreciated !!

TIA..

Nov 13 '06 #2
Thanks Ron !! It worked !!
I appreciate your quick response !!

RSH wrote:
Christina,

You have to set the ID property of the textbox. You are creating a textbox
object and then referring to it in code but from the perspective of the form
it has no ID so .Net is making and ID up which doesn't align with the name
you have given it.

Dim txtEmailAddress As New TextBox

txtEmailAddress.ID = "txtEmailAddress" <---- Add this

PlaceHolder2.Controls.Add(txtEmailAddress)

Dim ReqFieldVal As New RequiredFieldValidator

ReqFieldVal.ControlToValidate = "txtEmailAddress"

ReqFieldVal.ErrorMessage = "Required"

PlaceHolder2.Controls.Add(ReqFieldVal)

HTH,

Ron

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hello !!

I am creating a dynamic textbox and want to validate it using the
requiredfieldvalidator.

These are the steps which I tried:
================================================== ==
1) In Page_load,

Dim Email As New Label
Email.Text = "* Email Address"
placeHolder1.Controls.Add(Email)

Dim txtEmailAddress As New TextBox
placeHolder2.Controls.Add(txtEmailAddress )
2) The HTML has:
<tr><td>
<asp:PlaceHolder ID="placeHolder1" Runat="server"></asp:PlaceHolder>
<asp:requiredfieldvalidator id="reqFieldVal1" runat="server"
Display="Dynamic" ErrorMessage="Required"
ControlToValidate="txtEmailAddress"></asp:requiredfieldvalidator>
</td>
</tr>

================================================== ==

This gives an error message :

Unable to find control id 'txtEmailAddress' referenced by the
'ControlToValidate' property of 'reqFieldVal1'.
I tried the following options, but was unsuccessful:

a) Move requiredFieldValidator inside placeholder. (Googling around,
suggested that the validator and control should be in the same
container)

b) Tried to create requiredFieldValidator dynamically and add it in the
same placeholder (ie placeHolder1)

Any pointers will be appreciated !!

TIA..
Nov 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bryan | last post: by
2 posts views Thread by zoneal | last post: by
1 post views Thread by Eugenio.Net | last post: by
1 post views Thread by Madhumitham | last post: by
4 posts views Thread by marisenthil | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.