Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
my code is


C#
<script type="text/javascript" language="javascript">

       $(document).ready(function () { 

          $('#Btnsignin').click(function () {

              var summary = "";
              summary += isvalidusername();
              summary += isvalidPassword();

              if (summary != "") {
                  alert(summary);
                  return false;
              }
              else {
                  return true;
              }
          })
      })
      function isvalidusername() {
          var temp = $("#Txtuser").val();
          if (temp == "") {
              return ("Please Enter UserName" + "\n");
          }
          else {
              return "";
          }
      }
      function isvalidPassword() {
          var temp = $("#Txtpassword").val();
          if (temp == "") {
              return ("Please Enter firstname" + "\n");
          }
          else {
              return "";
          }
      }


  </script>


please provide me solution
Posted
Updated 26-Oct-13 1:03am
v3

You have to use ready event is as below.


XML
<script type="text/javascript">
$(document).ready(function() {

//Your js code here

$('#Btnsignin').click(function () {
 
var temp = $("#Txtuser").val();

if (!temp.length)
{
   alert('Please Enter UserName')
}
         
 
})


});
</script>
 
Share this answer
 
v2
Comments
sanjaysgh 26-Oct-13 6:42am    
sir it is not working
Sampath Lokuge 26-Oct-13 6:51am    
Are there any errors on browser dev tools console ?
sanjaysgh 26-Oct-13 6:54am    
ok...
VICK 26-Oct-13 6:53am    
Sampath is right.. Try to debug using Browser's debugger.. and check.. there are the possibilities of Jquery reference not found etc.
Sampath Lokuge 26-Oct-13 6:53am    
And above code snippet you didn't close brackets properly after the ready event.Check that also.Ready event should apply for whole js code.Not just for the first method.
try all the ONload event of button and see whether its work or not :)
 
Share this answer
 
i am assuming that you are using server side asp.net controls if yes then

1. open your page in browser either in firfox or chorme then right click on page then click inspect element
2. inspect window will appear pick the control of inspecting an element and click on your button
3. when you click on your "Btnsignin" button this will show you the exact id of your button because if you are using server side contol browser will render the long id just just pick that id
4. use that id in your script instead of physical id in script..
OR
1. if you are using asp.net 4.0 then use ClientModeID="Static" property for your contols it will take care your script and will not render the autogenrated id in browser...

OR
the way to access the asp.net control in javascritp or in jquery is like below for example

C#
function isvalidusername() {
          var temp = $('<%=Txtuser.ClientID%>').val();
          if (temp == "") {
              return ("Please Enter UserName" + "\n");
          }
          else {
              return temp;
          }
      }
 
Share this answer
 
v3

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