B
Blibo Baggins
My app has custom validator, and validation summary controls.
When the custom validator fires, it displays the error message on the
form, but I can not get it to pop up a message box with the error,
even though I set ShowMessageBox = True.
Would someone please let me know what I am doing wrong.
I attach an (over simplified) example of similar code which has the
same problem.
Thanks in advance.
Neil
--- ASPX CODE ---
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="pl.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 48px;
POSITION: absolute; TOP: 40px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 88px; POSITION:
absolute; TOP: 88px" runat="server"
Text="Save"></asp:Button>
<asp:CustomValidator id="CustomValidator1" style="Z-INDEX: 104;
LEFT: 56px; POSITION: absolute; TOP: 144px"
runat="server" ErrorMessage="CustomValidator"
ControlToValidate="TextBox1"></asp:CustomValidator>
<asp:ValidationSummary id="ValidationSummary1" style="Z-INDEX: 105;
LEFT: 48px; POSITION: absolute; TOP: 192px"
runat="server" ShowMessageBox="True"></asp:ValidationSummary>
</form>
</body>
</HTML>
--- END ASPX CODE ---
-- ASPX.VB CODEBEHIND ---
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CustomValidator1 As
System.Web.UI.WebControls.CustomValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
If Not Me.TextBox1 Is Nothing _
AndAlso Not Me.TextBox1.Text Is Nothing Then
args.IsValid = False
CustomValidator1.ErrorMessage = Me.TextBox1.Text
Else
args.IsValid = False
End If
End Sub
End Class
-- END ASPX.VB CODEBEHIND ---
When the custom validator fires, it displays the error message on the
form, but I can not get it to pop up a message box with the error,
even though I set ShowMessageBox = True.
Would someone please let me know what I am doing wrong.
I attach an (over simplified) example of similar code which has the
same problem.
Thanks in advance.
Neil
--- ASPX CODE ---
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="pl.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 48px;
POSITION: absolute; TOP: 40px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 88px; POSITION:
absolute; TOP: 88px" runat="server"
Text="Save"></asp:Button>
<asp:CustomValidator id="CustomValidator1" style="Z-INDEX: 104;
LEFT: 56px; POSITION: absolute; TOP: 144px"
runat="server" ErrorMessage="CustomValidator"
ControlToValidate="TextBox1"></asp:CustomValidator>
<asp:ValidationSummary id="ValidationSummary1" style="Z-INDEX: 105;
LEFT: 48px; POSITION: absolute; TOP: 192px"
runat="server" ShowMessageBox="True"></asp:ValidationSummary>
</form>
</body>
</HTML>
--- END ASPX CODE ---
-- ASPX.VB CODEBEHIND ---
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CustomValidator1 As
System.Web.UI.WebControls.CustomValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
If Not Me.TextBox1 Is Nothing _
AndAlso Not Me.TextBox1.Text Is Nothing Then
args.IsValid = False
CustomValidator1.ErrorMessage = Me.TextBox1.Text
Else
args.IsValid = False
End If
End Sub
End Class
-- END ASPX.VB CODEBEHIND ---