ashish
ashish

Reputation: 543

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

Upvotes: 3

Views: 199

Answers (1)

Mohammad Nadeem
Mohammad Nadeem

Reputation: 9392

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.

Upvotes: 4

Related Questions