Solved

ASP.Net Login control validation with jQuery

Posted on 2014-03-10
1
1,084 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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now