Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am using JQuery to validate whether user is existing in the database.

The function is as follows:

JavaScript
function CheckUserID() {
           var Email;
           Email = $('#<%=txtEmail.ClientID%>').val();
           Page_ClientValidate();
           if (Page_IsValid) {
               ValidatorEnable(document.getElementById('<%=reqName.ClientID %>'), false);
               ValidatorEnable(document.getElementById('<%=reqEmail.ClientID %>'), false);
               $.ajax({
                   type: "GET",
                   async: false,
                   url: "CkeckUser.aspx",
                   data: "UID=" + Email,
                   cache: false,
                   success: function(resultMsg) {
                       $('#<%=hdnEmailID.ClientID%>').val($(resultMsg).find("#divEmail input[type='hidden']").eq(0).val());
                       if ($('#<%=hdnEmailID.ClientID%>').val() == '1') {
                           $('#<%=lblMsg.ClientID%>').text('Users exists');
                           return false;
                       }
                       else {
                           $('#<%=lblMsg.ClientID%>').text('Users doesnot exists');
                           return true;
                       }
                   },
                   error: function(msg) {
                       alert("Error");
                   }
               });
           }
           else {
               ValidatorEnable(document.getElementById('<%=reqName.ClientID %>'), true);
               ValidatorEnable(document.getElementById('<%=reqEmail.ClientID %>'), true);
               $('#<%=lblMsg.ClientID%>').text('');
           }
       }



It checks for the user existence (if user is existing it will show msg ..user exists.. and does postback to insert the value in database).

Any one can help (to avoid doing postback) when user is existing in database.

Thank you,
yashoda
Posted
Updated 30-Jun-11 8:14am
v2
Comments
Kiran Sonawane 30-Jun-11 2:44am    
Can you show your code where you calling CheckUserID javascript function

1 solution

CheckUserID() is not always returning a value. Add this line to the end of your function:
return false;

And how are you calling the function? You will need something like this:
<form name="frm1" onsubmit="return CheckUserID();"></form>

This will not work:
<form name="frm1" onsubmit="CheckUserID();"></form>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900