我有一个 aspx 内容页面,它由母版页继承。
在母版页中,我的主要内容占位符位于<form>
,
<form runat="server">
<div class="page">
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
以下是我的内容页面的代码:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td colspan="2" class="header" style="color: Black;">
LOGIN USER
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="lblUserName" runat="server" Text="UserName: "></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="lblPassword" runat="server" Text="Password: "></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<asp:Button ID="btnReset" runat="server" Text="Reset" />
</td>
</tr>
</table>
<div align="center" class="alertmsg">
</div>
虽然我要使用 jQuery 验证插件:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#ctl01').validate({
rules: {
<%=txtUserName.UniqueID %>: {
minlength: 2,
required: true
},
<%=txtPassword.UniqueID %>: {
required: true,
email:true
}
},
messages: {
<%=txtUserName.UniqueID %>:{
required: "* Required Field *",
minlength: "* Please enter atleast 2 characters *"
},
<%=txtPassword.UniqueID %>:{
required: "* Required Field *",
email: "* Please enter valid email address *"
}
}
});
});
</script>
的动态idtxtUserName
可以被暴露出来<%=txtUserName.UniqueID %>
,但是为什么我需要给表单的id$('#ctl01').validate
呢?我可以使用任何其他 id 代替#ctl01
吗?