Solved

ASP.Net Login control validation with jQuery

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Linq - Join two objects into one 3 31
Query in AngularJS 8 41
Securing WEBAPI on Azure 2 17
Build a string of emails from a gridview 2 12
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

679 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