Beruflich Dokumente
Kultur Dokumente
C# Corner
Visual Studio 2017 Live
Using JavaScript
Siddu Soraganvi Jun 05 2017 Blog
2 0 10.3k
Today we are going to learn how to validate the Text Box using the java script
in asp.net.
First create the Text box and one button in your aspx �le as I have written the
code to create the text box and button below.
ASP.Net Code
01. <body>
02. <form id="form1" runat="server">
03. <div>
04.
05. <table class="style1">
06. <tr>
07. <td>
08. <asp:Label ID="Label1" runat="server" Text="User Name">
</asp:Label>
09.
10. <asp:TextBox ID="txtUName" runat="server"></asp:TextBox>
11. </td>
12. </tr>
13. <tr>
14. <td>
15. <asp:Label ID="Label2" runat="server" Text="Password">
</asp:Label>
16.
17. <asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
18. </td>
19. </tr>
20. <tr>
21. <td>
22.
23. <asp:Button ID="btnLogin" runat="server" Text="Login" Width="120px"
24. OnClientClick="return userValid();" />
25. </td>
26. </tr>
27. </table>
28.
29. </div>
30. </form>
31. </body>
In Focus
C# Corner
Visual Studio 2017 Live
01. <script type="text/javascript">
02.
03. function userValid() {
04. var UName= document.getElementById("txtUName").value;
05. var Pwd= document.getElementById("txtPwd").value;
06.
07. if (UName == '')
08. {
09. alert("Please enter User Name");
10. return false;
11. }
12.
13. if (Pwd == '')
14. {
15. alert("Please enter Password");
16. return false;
17. }
18. }
19. </script>
Siddu Soraganvi
1656 22.7k
2 0
In Focus
C# Corner
Visual Studio 2017 Live
LATEST BLOGS
.NET Core - Basic Information
Microsoft Flow - Recurring Work�ow To Copy Files From Local Shared Path To
SharePoint Document Library
View All
In Focus
C# Corner
Visual Studio 2017 Live
Philadelphia
New York
London
Delhi
Join C# Corner
and millions of developer friends worldwide.