473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 9338
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

0
by: Stephen | last post by:
I have the following textbox in the footer of a Datagrid and I'd like to try and add some client side code too take out all the spaces which the user might enter by accident. The textbox is used...
1
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
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
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
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
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
by: Madhumitham | last post by:
textbox validation (to enter numbers) in vb.net in both client side and server side
9
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.