Required field:

<asp:textbox id="textbox1" runat="server"/>
<asp:RequiredFieldValidator id="valRequired" runat="server"
ControlToValidate="textbox1" ErrorMessage="* Please enter a value" Display="dynamic">*

how can i put the vlidation correctly

Edited by __avd: Added [code] tags.

5 Years
Discussion Span
Last Post by dnanetwork

Hi, what seems to be the problem?

What the code you posted does is ...
once a buttonis clicked,
it will check if textbox1 is empty, if it is empty it will show the ErrorMessage.

If you want to validate for correct input, use RegularExpressionValidator

Hope this helps.


keyur.smith just explain your exact requirement for validation. Then we will help you better.

Edited by Ezzaral: Snipped promotion links.


Dear the asp.net validation occurs on the client side for asp.net controls
The validation occurs usually on button click , you can set the button and controls intended to be validated in the same validation group
you can prevent the button click validation by set the property causes validation to false , for example the auto post back for check box or auto post back of drop down list can cause validation by set the causes validation to true of check box and drop down list asp.net controls
Now the above validation you mentioned you can extend by controls on AJAX Control Toolkit , to have a better look and feel

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.