Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.Net Login control validation with jQuery

Posted on 2014-03-10
1
Medium Priority
?
1,148 Views
Last Modified: 2014-03-11
1. I have a front page template

http://www.coralixthemes.com/themeforest/html/medical/template/index.html

If you click on "Make an appointment now", without entering anything in the fields, the fields get validated. It's done by calling "index1-validation.js".

That form is not a server side form. Doesn't have "runat=server"

2. I took that page and changed that section by adding an ASP.Net login control.

     http://arms.staging.firehost.com/default2.aspx

    That login is a server side control.
   
  <form class="col-md-7 col-lg-6"  runat="server" id="frmLogin"  action="/">

Open in new window


   I changed "index1-validation.js" to this

 
 $().ready(function() {

	// validate signup form on keyup and submit
	$("#frmLogin").validate({
		rules: {
			Login1$UserName: "required",
			.......
		},
		messages: {
			Login1$UserName: "Please enter your fullname",
			......		}
	});
});

Open in new window



Now, when I click on "submit", I want to do validation first but it calls the server (I don't have code behind the submit yet, you'll get page not displayed)

I think I need to do something like this
http://encosia.com/using-jquery-validation-with-asp-net-webforms/

First, make sure the form is valid, set isValid variable. If not valid, prevent the form from being submitted.

I don't know if that's correct and if so, where all this would go?
0
Comment
Question by:Camillia
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39920166
Try changing your jquery to the following to prevent the form submitting:
$().ready(function() {

	// validate signup form on keyup and submit
	$("#frmLogin").validate({
		rules: {
			Login1$UserName: "required",
			.......
		},
		messages: {
			Login1$UserName: "Please enter your fullname",
			......		}
	});
    $("#frmLogin").on('submit', function(e){
        var isValid=$("#frmLogin").valid();
        if(!isValid)
        {
            // prevent postback
            e.preventDefault();
        }
    });
});

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question