Question

I am currently building a ASP.NET C# form. This form had many fields and many validations. Which included:

  • Validate when the required checkbox is checked
  • Validate a dynamic form (e.g. additional address form generate dynamically when add address button click)

At first, I was planning to use ASP.NET form control to create all the fields and validations. But later on I found there is a plugin call jqueryvalidation, which simply provided what I need through Jquery.

and my question is, if I am going to use this, would it be easier for me to create the form using standard HTML form tag instead of .NET control? Or can I still use .NET control?

I am quite struggle as I want to use the .NET control because I can obtain the value easily in code behind instead of Request.Form["fieldName"] but on the other hand, I feel not convenience to use the validation that .NET provided and I am not sure whether .net can create a dynamic form as easy as Jquery either.

Please advise. Thanks!

No correct solution

OTHER TIPS

with validation plugin you can use "when required" case like this

 $('#formSubmit').validate({ 
    rules: {
        ControlAspNetorSmtin: {
            required: {
                depends: function (element) {
                    if ($('#chkglobal').is(':checked')) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }


        }.... etc

If you are using ASP.NET MVC (which you probably should be) then your best bet would be to use auto-magic validation using model validation attributes and unobtrusive-validation. This would take care of client- and server-side validation with minimal effort (apart from defining the attributes).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top