tags:

views:

41

answers:

2

I have a Login Page Contains two text boxes one is user name,password and one button if the two textboxes are empty that time how i can avoid post back of the buuton if any value enterd that time only postback occuers,,,, not using required fiekd validator any method is avilable in javascript.......

A: 

yes according to me you can do one thing is to check for the check box values when clicking button

html part

<asp:button onclientClick="return onclick()" id="btnLogin" runat="server" >

or in cs file

btnLogin.attribute.Add("onclick","return onclick()");




function onclick()
{
  if(("#username").val()==="")//document.getElementById("username").value
    return false;
  if(("#password").val()==="")//document.getElementById("password").value
    return false;

  return true;
}

use commented part to get value if you are not using jquery

Pranay Rana
for this solution you must link jquery file in your code
Space Cracker
A: 

use jquery and the following code also do what you want

$(document).ready(function() {
        // Save Button
        $('#<%= TestButton.ClientID %>').click(function(e) {
        var username = $('#<%= usernameTextBox.ClientID %>').val();
        var email = $('#<%= passwordTextBox.ClientID %>').val();
        if ( username.length == 0 || email.length == 0 ||) {
                e.preventDefault();
        });
}
Space Cracker