views:

39

answers:

1
<%@ 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

+4  A: 

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.

Nadeem
@Nadeem: thanks nadeem now it is working fine :) can you tell me why we should use this
ashish
@ashish : See the edited answer.
Nadeem
@nadeem: why these ids getting changed only in reference of masterpage while this code is working fine with a simple page..
ashish
The reason ids are changed is that you may have a control with same id on mater and content page.
Nadeem