Shivprasad Koirala
.NET/ASP.NET Interview Question -How can we Validate a Controls in ASP.NET page using JavaScript?
By Shivprasad Koirala in ASP.NET on Apr 28 2011
  • Shirsendu Nandi
    May, 2011 2

    Online backup: For eg Database replication

    OffLine BackUp:Restrong database in to stroring device

     

    • 0
  • Shirsendu Nandi
    May, 2011 2

    Online backup: For eg Database replication

    OffLine BackUp:Restrong database in to stroring device

     

    • 0
  • Shivprasad Koirala
    Apr, 2011 28

    Answer:
     

    Let's see an Simple example to understand.

    Assuming that we have a Textbox and Button on the ASP.NET page like below.

    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit"
    OnClientClick="return validate()" />


    Now, Add the below code snippet on the page source.

    <script language="javascript" type="text/javascript">
    function ValidateTextBox()    
    {
       if(document.getElementById("<%=txtName.ClientID%>").value == "")         
      {                
    alert("Name Field Cannot be Empty");
       document.getElementById("<%=txtName.ClientID%>").focus();
        return false;      
       }
        return true;
    }
    </script>


    Once you have completed the above steps, just run the project and see the result.

     Regards,

    Please click here to see more .NET/ASP.NET interview questions


    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS