Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 859
ashish Avatar asked May 31 '26 23:05

ashish


1 Answers

Try

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

You need to do this because id of the control on the content page gets changed. Try viewing the source of your page and you can see the changed ids.

like image 181
Mohammad Nadeem Avatar answered Jun 03 '26 12:06

Mohammad Nadeem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!