Solved

ASP.Net Login control validation with jQuery

Posted on 2014-03-10
1
1,061 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now