Required Field?

K

Kivak Wolf

Hi,

Could someone give me a quick review of how to use the required field
Validator? I'm completely at a loss, and MSDN does not help one bit. =/
Basically all I want done is to make sure that the user enters some
text into a field called "txbName" and when they click on the submit
button, if they have not entered anything into the field, a Required
Field Validator will say "Invalid Name".

Thanks,
Kivak Wolf
 
C

Curt_C [MVP]

Kivak said:
Hi,

Could someone give me a quick review of how to use the required field
Validator? I'm completely at a loss, and MSDN does not help one bit. =/
Basically all I want done is to make sure that the user enters some
text into a field called "txbName" and when they click on the submit
button, if they have not entered anything into the field, a Required
Field Validator will say "Invalid Name".

Thanks,
Kivak Wolf

- Toss the validator on the page.
- Assign it's control to validate to your txtBox
- Give the validator an error messsage.
- I like to put a Validation Summary control on the page to centralize
the messages.
- compile, run.
 
G

Grant Merwitz

as simple as this:


<asp:requiredfieldvalidator id="ReqValtxbName" runat="server"
EnableClientScript="True" Display="Dynamic" ControlToValidate="txbName"
ErrorMessage="Invalid Name"></asp:requiredfieldvalidator>
 
P

Peter Blum

While I agree with the other answers, there is one more step. Always setup
server side validation because you cannot assume all browsers visiting your
site will run the client-side javascript supplied by Microsoft. In fact,
only IE and IE/Mac support their javascript in ASP.NET 1.x.

I've put together an article to educate users on validation. It discusses
setting up server side validation with examples and issues with client-side
validation. www.aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top