I made an ASP.NET form wizard that contains multiple pages of fields. Some of these fields are meant to be required and some are meant to be optional. By default the wizard seems to make every field required. How do I change them to optional?
I assumed that required=false
in <input runat="server" ID="txtDriverLicenseNumber" type="text" required="false" size="24"></input>
would have the desired effect, but it seems to do nothing.
Additionally, I would like the form to allow me to hit "previous" even if I did not fill out the fields on the current page.
Some assistance would be greatly appreciated!
HTML5 attribute
required
forinput
fields is validated on the client side (browser). Not all browsers do. Don't include the attribute if you don't want it to be reqiured (leave it out, don't sayrequired="false"
)This input is required:
This input is not required:
You can use the attribute in HTML server controls or ASP.Net controls to add client side validation for browsers that do support it:
Use on HTML server control:
Use on ASP.net control:
This is how Firefox (v12) renders validation of
required
attribute (your screen shot is Chrome?):You can use ASP.Net Validation Controls to validate both HTML server and ASP.net controls on the server (aka server-side validation) and is what you should do in order to properly validate your inputs.
Server side validation will work regardless of whether or not the browser supports HTML5
required
attribute:Server side validation (required) of ASP.Net HTML server control:
Server side validation (required) of ASP.Net control:
Validation will control your progress through the ASP.Net Wizard - required fields (only) must be provided for you to go to the "next step" (and back). That is how it should work.
I think you're just experiencing difficulty because you have made all your fields required in error (because you are setting the
required="false"
attribute instead of omitting it and you are using Chrome - which does validate it).Hth...