我在更新面板中有几个文本框,我正在为此做一些简单的验证。如果验证检查失败,则会在对话框中弹出错误消息。我的问题是当其中一个文本框的验证失败但另一个文本框没有验证时,RegisterClientScriptBlock 会显示对话框。在这两种情况下,事件都会触发。在下面的代码中,当 txtCustMSCName(外部 If 语句的 Else 下面的第二个)文本框未通过验证条件时,对话框正确显示,但在 txtMSCName 文本框失败时不显示。任何想法为什么会发生这种情况?这与 txtMSCName 设置为 ReadOnly=True 的事实有关吗?
VB:
If chkCustomMSC.Checked = False Then
If txtMSCName.Text = "No sales contact for this account" Then
DialogMsg = "alert('There are no main sales contacts for this account in CRM; please check the 'Custom MSC' box and " _
+ "manually enter the main sales contact information');"
ErrorDialog(DialogMsg)
Exit Sub
End If
Else
If txtCustMSCName.Text = "" Then
DialogMsg = "alert('You must enter a main sales contact name');"
ErrorDialog(DialogMsg)
Exit Sub
End If
End If
Protected Sub ErrorDialog(ByVal Message As String)
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), Message, True)
End Sub
标记:
<asp:TextBox ID="txtMSCName" runat="server" ReadOnly="true" CssClass="DisplayTextBoxStyle"/>
<asp:TextBox ID="txtCustMSCName" runat="server" CssClass="MSCInputTextBoxStyle"/>