我是asp.net的新手并面临一些小问题。问题是设置Textbox
和label
处于不同的位置,而我使用<br/>
标签表单看起来非常糟糕,我该如何解决流程?
代码是:
<tr>
<td align="right" style="padding-right: 5px;" class="style6">
<asp:Label ID="lblEmailId" runat="server" Text="EMAIL ID :"></asp:Label>
</td>
<td align="left" style="padding-left: 5px;" class="style6">
<br/><br/><br/>
<asp:TextBox ID="txtEmailId" runat="server" Width="70%" AutoCompleteType="Office"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmailId"
ErrorMessage="You can't leave this empty." Style="color: #FF0000;"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rfvEmailId" runat="server" ControlToValidate="txtEmailId"
ErrorMessage="Not a Valid Email Address" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="CreateUserWizard1" Style="color: #FF0000;" /> <br />
</td>
</tr>
<tr>
<td colspan="2">
<br />
</td>
</tr>
<tr>
<td align="right" style="padding-right: 5px; " class="style6">
<asp:Label ID="lblPhoneNo" runat="server" Text="PHONE NO. :"></asp:Label>
</td>
<td align="left" style="padding-left: 5px; " class="style6">
<asp:TextBox ID="txtPhoneNo" runat="server" Width="70%" AutoCompleteType="Office"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPhoneNo"
ErrorMessage="You can't leave this empty." Style="color: #FF0000;"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rfvPhoneNo" ControlToValidate="txtPhoneNo" ValidationExpression="\d{10}"
ErrorMessage="The number must be 10 numeric digits!" runat="server" Style="color: #FF0000;" />
</td>
</tr>
PLZ可以帮助我解决这个问题......,
答案 0 :(得分:1)
在同一个<tr>
元素中,标签位于一个<td>
中,文本框位于另一个{...}中:
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server" />
</td>
</tr>
<tr>
<td>
Surname
</td>
<td>
<asp:TextBox ID="txtSurname" runat="server" />
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
<asp:TextBox ID="txtAge" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: right;">
<asp:Button ID="btnAdd" runat="server" Text="Add" />
</td>
</tr>
</table>
生成以下布局:
答案 1 :(得分:0)
删除<br/><br/><br/>
实际上,不要使用设计师进行布局!仅用于预览和添加新的自定义控件。
答案 2 :(得分:0)
<br />
和
代码。设置RequiredFieldValidator和RegularExpressionValidator动态显示
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmailId"
ErrorMessage="You can't leave this empty." Style="color: #FF0000;" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rfvEmailId" runat="server" ControlToValidate="txtEmailId"
ErrorMessage="Not a Valid Email Address" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="CreateUserWizard1" Style="color: #FF0000;" Display="Dynamic"/>