<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SignIn.aspx.cs" Inherits="DSN.SignIn" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Avopo DSN Platform::登录</title> <script type="text/javascript"> window.onload = function(){ var str=window.location.href; var es=/skin=/; es.exec(str); var right=RegExp.rightContext; if(right=='0') { alert("该帐号已在别处登陆,你被强迫下线"); window.location.href=window.location.href.split("?")[0]; } } </script> <script type="text/javascript"> function reloadImage(url) { var img = document.getElementById("<%=ImageCode.ClientID%>"); alert(img); img.src = url+"?" + Math.random(); } </script> </head> <body> <form id="form1" runat="server"> <div class="allcontent"> <div class="header-wrap"> <div class="header"> <a class="logo" href="/"></a> </div> </div> <div class="content-wrap1"> <div class="content-login"> <div class="content-bg"> <asp:Login ID="Login" runat="server" CreateUserUrl="~/NewUser.aspx" FailureText="登陆失败,请重试." SkinID="Login" DestinationPageUrl="~/Default.aspx"> <LoginButtonStyle CssClass="button" /> <TextBoxStyle CssClass="textBox" /> <LayoutTemplate> <table align="center" border="0" width="100%" cellpadding="6"> <tr> <td> <asp:Panel ID="panFocus" runat="server" DefaultButton="LoginButton"> <table border="0" cellpadding="2"> <tr> <td align="left"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label> </td> <td> <asp:TextBox ID="UserName" runat="server" CssClass="textBox" Width="155px"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="left"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密 码:</asp:Label> </td> <td> <asp:TextBox ID="Password" runat="server" CssClass="textBox" TextMode="Password" Width="155px"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login">*</asp:RequiredFieldValidator> </td> </tr> <%--验证码--%> <tr> <td></td> <td> <asp:Image ID="ImageCode" runat="server" ImageUrl="~/IdentifyingCoding.aspx" /> <a href="javascript:reloadImage('IdentifyingCoding.aspx');">换一张</a> <%--验证码--%> </td> </tr> <tr> <td align="left" colspan="2" style="color: red"> <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal> </td> </tr> <tr> <td align="left"> <asp:CheckBox ID="RememberMe" runat="server" Text="下次登录记住我" CssClass="noborder" /> </td> <td align="right" c> <asp:Button ID="LoginButton" runat="server" CommandName="Login" CssClass="button" Text="登 录" ValidationGroup="Login" /> </td> </tr> <!-- <tr> <td align="left" class="linkNewUser" colspan="2"> <asp:HyperLink ID="CreateUserLink" runat="server" NavigateUrl="~/NewUser.aspx">还没注册?</asp:HyperLink> </td> </tr>--> </table> </asp:Panel> </td> </tr> </table> </LayoutTemplate> </asp:Login> </div> </div> </div> <div class="footer-wrap"> <div class="footer"> <a href="http://www.avopo.com" target="_blank" class="logo"> <img id="Img2" alt="logo" src="~/images/logo.png" runat="server" height="30" border="0" /></a> <a href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=176" class="footerLink" target="_blank">联系我们</a> | <a class="footerLink" href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=177" target="_blank">责任声明</a> | <a class="footerLink" href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=178" target="_blank">网站所有者信息</a> | 京ICP备11029852号 <br /> Copyright ©2010~2011 Avopo Technologies. All Right Reserved. </div> </div> </div> <%--<table width="980" cellpadding="0" cellspacing="0" align="center" class="signinbody"> <tr> <td> <table cellpadding="0" align="center" cellspacing="0" border="0" width="980" id="signinheader"> <tr> <td width="5%"> </td> <td width="45%" align=left valign="bottom"> </td> <td width="50%"> </td> </tr> </table> <table cellpadding="0" align="center" cellspacing="0" id="signincontent" border="0"> <tr> <td width="50%"> </td> <td width="50%"> <table cellpadding="0" align="left" cellspacing="0" border="0" > <tr> <td class="signincontainer" valign=bottom> <asp:Login ID="Login" runat="server" CreateUserUrl="~/NewUser.aspx" FailureText="登陆失败,请重试." SkinID="Login" DestinationPageUrl="~/Default.aspx"> <LoginButtonStyle CssClass="button" /> <TextBoxStyle CssClass="textBox" /> <LayoutTemplate> <table align="center" border="0" width="100%" cellpadding="6"> <tr> <td> <asp:Panel ID="panFocus" runat="server" DefaultButton="LoginButton"> <table border="0" cellpadding="2"> <tr> <td align="left" > <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label></td> <td> <asp:TextBox ID="UserName" runat="server" CssClass="textBox" Width="155px"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="left" > <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密 码:</asp:Label></td> <td> <asp:TextBox ID="Password" runat="server" CssClass="textBox" TextMode="Password" Width="155px"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="left" colspan="2" style="color: red"> <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal> </td> </tr> <tr> <td align="left" > <asp:CheckBox ID="RememberMe" runat="server" Text="下次登录记住我" CssClass="noborder"/> </td> <td align="right" c> <asp:Button ID="LoginButton" runat="server" CommandName="Login" CssClass="button" Text="登 录" ValidationGroup="Login" /> </td> </tr> <!-- <tr> <td align="left" class="linkNewUser" colspan="2"> <asp:HyperLink ID="CreateUserLink" runat="server" NavigateUrl="~/NewUser.aspx">还没注册?</asp:HyperLink> </td> </tr>--> </table> </asp:Panel> </td> </tr> </table> </LayoutTemplate> </asp:Login> </td> </tr> </table> </td> </tr> </table> <table cellpadding="0" align="center" cellspacing="0" id="signinfill" border="0"> <tr> <td width="*"> </td> <td align="right" width="100" valign="center"> <a href="http://www.avopo.com" target="_blank" class="logo"> <img id="Img1" alt="logo" src="~/images/logo.png" runat="server" height="30" border="0" /></a> </td> <td align="right" width="590" valign="center"> <a href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=176" class="footerLink" target="_blank">联系我们</a> | <a class="footerLink" href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=177" target="_blank">责任声明</a> | <a class="footerLink" href="http://www.avopo.com/lsxy/ShowArticle.asp?ArticleID=178" target="_blank">网站所有者信息</a> | 京ICP备11029852号 <br />Copyright ©2010~2011 Avopo Technologies. All Right Reserved. </td> </tr> </table> </td> </tr> </table>--%> <%-- <script language="javascript" type="text/javascript"> window.onload = function() { AdjustSize(); } window.onresize = function() { AdjustSize(); } function AdjustSize() { var height = document.documentElement.clientHeight; var content = document.getElementById("signincontent"); var fill = document.getElementById("signinfill"); fill.style.height = height - content.offsetTop -content.offsetHeight + "px";// - content.offsetTop - footer.style.marginTop - footer.style.marginBottom - content.style.marginTop - 20 + "px"; } </script>--%> </form> </body> </html>
为什么所有登陆控件中的控件的id全都获取不到?下面是一个例子:
到底是为什么?不明白啊!
我已经解决问题了,原因是登陆页面是用Login控件写的,凡是放在里面的服务器控件都无法获取客户端id,只需将添加的控件换成客户端控件,同时直接通过document.getElementById("ImageCode")便可以获取用户控件了。
把head里 runat=server去掉
不要加ClientID,直接获取ID试试
在后台手动添加
protected System.Web.UI.WebControls.Image ImageCode;