<%@ 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" />
然后我收到了错误:: Microsoft JScript运行时错误:需要对象
答案 0 :(得分:4)
尝试
var uname = document.getElementById("<%=txtUName.ClientID%>").value;
您需要这样做,因为内容页面上控件的ID会发生变化。尝试查看您的页面来源,您可以看到更改的ID。