473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6439
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5295
by: Bryan | last post by:
I trying to figure out out to validate a textbox inside a repeater once a person presses a button on a repeater. Here's the validation Code behind: Please be aware that line e.Item.ItemIndex...
1
1945
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
2
1299
by: zoneal | last post by:
Anyone can help me how to do dynamic textbox appearance? need it for matrix data entry, suppose i enter 3 and 4 then the 3x4 textboxes will appear.. thank you very much.
1
1292
by: Eugenio.Net | last post by:
Hello all I'm using a button to validade a TextBox but I already saw some websites that validation is automaticaly after 4 or 5 chars... How can I validate my textox to call a function??? ...
2
9342
by: Christina | last post by:
Hello !! I am creating a dynamic textbox and want to validate it using the requiredfieldvalidator. These are the steps which I tried: ==================================================== 1)...
1
1119
by: Madhumitham | last post by:
textbox validation (to enter numbers) in vb.net in both client side and server side
9
4000
by: kumarrk | last post by:
Hi all, i am using place holder for dynamic textbox and label box, then when i enter the values in textbox then i click the add button and save to database, but i couldnt get the dynamic textbox...
9
35640
mageswar005
by: mageswar005 | last post by:
Hi Guys, My array textbox validation is not working fine,my code is given below please help me immediately. function validation() { var chks =...
4
2269
by: marisenthil | last post by:
How to access the value of the dynamic textbox by its id? I created more dynamic textbox using the below in loop Dim tb As New TextBox tb.ID = "txt_" + Str$(i) and it assigned unique...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.