【发布时间】:2015-06-09 10:24:15
【问题描述】:
我在 asp.net 中有一个面板,该面板只有在特定文本框具有经过验证和接受的输入时才可见。在所有其他情况下,它应该保持隐藏。
文本框及其验证的代码是:
<td class="auto-style4" align="left">
ID:
<br />
</td>
<td class="style10">
<asp:TextBox ID="TextBox1" runat="server" CssClass="txtbox" Height="25px" Width="200px" >
</asp:TextBox>
</td>
<td >
<asp:Panel ID="Panel1" runat="server" style="display: block;">
<asp:requiredfieldvalidator ID="RequiredFieldValidator1" ForeColor="Red" ErrorMessage="Please enter valid bug ID." Display="Dynamic" ControlToValidate="TextBox1" runat="server" SetFocusOnError="true">* </asp:requiredfieldvalidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ForeColor="Red" ControlToValidate="TextBox1" ErrorMessage="Bug ID should be numeric." runat="server" Display="Dynamic" SetFocusOnError="true" ValidationExpression="^\d+$">*</asp:RegularExpressionValidator>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" style="display: block;">
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" ForeColor="Red" ControlToValidate="TextBox1" ErrorMessage="Bug ID should be numeric." runat="server" Display="Dynamic" SetFocusOnError="true" ValidationExpression="^\d+$">*</asp:RegularExpressionValidator>
</asp:Panel>
</td>
我写了一个函数来检查它是否是一个数字,因为我不确定是否可以在下面给出的代码中直接检查验证:(要显示的面板是 Panel3)
Protected Sub RBL_EnterBugID_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RBL_EnterBugID.SelectedIndexChanged
If RBL_EnterBugID.SelectedItem.Text = "Yes" Then
Panel1.Visible = True
Panel2.Visible = False
If IsInputNumeric(TextBox1.Text) Then
Panel3.Visible = True
Else
Panel3.Visible = False
End If
Else
Panel1.Visible = False
Panel2.Visible = True
Panel3.Visible = False
Panel5.Visible = True
End If
End Sub
我是 asp.net 的新手,我们将不胜感激。谢谢。
【问题讨论】:
-
您在执行此操作时是否遇到任何错误?
-
不,我没有遇到任何错误;但是面板永远不会变得可见
-
尝试在
RBL_EnterBugID_SelectedIndexChanged设置一个断点,看看你得到了什么结果
标签: asp.net vb.net validation