开发者

Javascript using asp.net

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 vali开发者_如何学运维dator any method is avilable in javascript.......


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();
        });
}


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()
{
  var bool = true;
  if($("#username").val()==="")//document.getElementById("username").value
    bool = false;
  if($("#password").val()==="")//document.getElementById("password").value
    bool = false;

  return bool;
}

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜