在aspx页面中正常,于是我把代码分离到ascx里。
代码如下:
UserLogin.ascx
- C# code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserLogin.ascx.cs" Inherits="UserLogin" %>
<form id="form1" name="form1" runat="server" method="post" >
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="177"> <img src="img/yhdl.jpg" width="177" height="47" /> </td>
</tr>
<tr>
<td width="177" align="right" background="img/yhdlbg.jpg" style="height: 25px"> <table width="90%" height="25" border="0" cellpadding="0" cellspacing="0" class="zt">
<tr>
<td align="center" style="height: 37px">用户名: </td>
<td style="height: 37px; text-align: left"> <label>
<asp:TextBox ID="UserName" runat="server" Height="13px" Width="78px" > </asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName"
ErrorMessage="*"> </asp:RequiredFieldValidator> </label> </td>
</tr>
</table> </td>
</tr>
<tr>
<td width="177" height="25" align="right" background="img/yhdlbg.jpg"> <table width="90%" height="25" border="0" cellpadding="0" cellspacing="0" class="zt">
<tr>
<td align="center" style="height: 25px">密 码: </td>
<td style="height: 25px; text-align: left"> <label>
<asp:TextBox ID="Password" runat="server" Height="13px" TextMode="Password"
Width="78px"> </asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Password"
ErrorMessage="*"> </asp:RequiredFieldValidator> </label> </td>
</tr>
</table> </td>
</tr>
<tr>
<td width="177" height="35" align="center" background="img/yhdlbg.jpg"> <table width="85%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" colspan="2" style="height: 20px">
<label>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/dl.jpg" OnClick="ImageButton1_Click" /> </label> <label> </label> </td>
</tr>
</table> </td>
</tr>