Client side validation error

<%@ Page Language="C#" MasterPageFile="~/HomeMaster.master" AutoEventWireup="true" CodeFile="HomePage.aspx.cs" Inherits="Default2" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cp1" Runat="Server">

<script language="javascript" type="text/javascript">
    function checkInput()  
{  
  var uname = document.getElementById("txtUName").value;  
  var pwd = document.getElementById("txtPWord").value;  
  var counter=0;  
  if(uname.length==0) counter++;  
  if(pwd.length==0) counter++;  
  if(counter > 0)  
   {
   document.getElementById("dvError").innerHTML = "user name or password can not be blank" ;
        // alert("blank field");  

      return false;
    }
   return true; 
   }  


    </script>
   <div id="dvError"  style="height: 102px; color:Red; "  ></div>


**on button click::**
<asp:Button ID="btnSin" runat="server" Text="SignIn" OnClientClick="return checkInput()" onclick="btnSin_Click" />

then I got an error :: Microsoft JScript runtime error: object required

+3
source share
1 answer

Try

var uname = document.getElementById("<%=txtUName.ClientID%>").value;  

You need to do this because the identifier of the control on the content page has changed. Try viewing the source of your page and you will see the changed identifiers.

+4
source

Source: https://habr.com/ru/post/1766336/


All Articles