注册 登录
编程论坛 ASP.NET技术论坛

关于引用了母版页后,怎么在内容页里写javascript的验证表单的代码?

hh_melon 发布于 2007-09-24 17:32, 1165 次点击

就是我写javascript的表单验证的时候,
因为用到了母版页,
所以就不能像平常一样的那么写了。
<script language="javascript" type="text/javascript">
function Check()
{
if (document.form1.TextBox2.value.length==0)
{
alert("用户号不能为空");
document.form1.TextBox3.value="";
document.form1.TextBox2.focus();
return false;
}
if(isNaN(document.form1.TextBox2.value))
{
alert("用户号必须全部为数字");
document.form1.TextBox2.value="";
document.form1.TextBox3.value="";
document.form1.TextBox2.focus();
return false;
}
if(document.form1.TextBox3.value.length==0)
{
alert("用户的密码不能为空!");
document.form1.TextBox3.focus();
return false;
}
return true;
}
</script>


下面是内容页的开始的部分:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/ParentMaster.master" CodeFile="ApplerLetter.aspx.cs" Inherits="ApplerLetter" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" ID="register" runat="server">

<script language="javascript" type="text/javascript">
function Check()
{
// if (document.form1.txtUserID.value.length==0)
// {
// alert("用户号不能为空");
// document.form1.txtUserID.value="";
// document.form1.txtUserID.focus();
// return false;
// }
alert("不成功");

return true;
}
</script>

<div>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
用户申请填写信息如下:<br />
<hr style="width: 738px" align="left" color="red" />
<table>
<tr>
<td>用户编号:
</td>
<td>
<asp:TextBox ID="txtUserID" runat="server"></asp:TextBox>
</td>


1 回复
#2
zklwzh2007-09-27 13:54

前段遇到这个问题,去网上搜了一下。有两种解决办法:1。打开源文件,找到对象,你会发现其ID自动加ct100_母版页的容器名_元素ID。记下它。然后再使用。2。documen.getElementById('<%=对象ID。ClientID%>')进行操作。

1