ValidationSummary does not show message box when ShowMessageBox is true

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 ---
 
K

Ken Cox [Microsoft MVP]

Hi Neil,

Looks like a bug... I couldn't make it work either.

I'll pass it along to a contact at MS to see what they say.

Ken
MVP [ASP.NET]
 
M

Marcelo Dabanovich Lavio

Hi Neil,

I think that you should try to add a client side script validation function
to your custom validator. It may happen that the ValidationSummary control
can only show the message box (which is a client side script call to
window.alert()) if the client side validation fails (and the page is not
submitted).

In your case, you only have server side validation (for the custom
validator) and you only see the error message after the page is re-sent to
the browser after the server-side validation. It may be a bug (of
ValidationSummary control implementation) to not show the message box if the
page is being rendered with an error message generated by server side
validation, but I think adding client side validation (if possible) for your
custom validator may be a useful workaround.

Hope this helps.
Marcelo
 
J

JustMe

Microsoft confirmed to me that this IS a bug. There will not be a
quickfix, so you have to use one of the workarounds mentioned at
http://khsw.blogspot.com/2004/09/bug-in-aspnet-validator_07.html

Kind regards

Ken Cox said:
Hi Neil,

Looks like a bug... I couldn't make it work either.

I'll pass it along to a contact at MS to see what they say.

Ken
MVP [ASP.NET]

Blibo Baggins said:
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 ---
 
S

Steven Burton

This link considers a completely different problem and does address the
ShowMessageBox problem at all.

JustMe said:
Microsoft confirmed to me that this IS a bug. There will not be a
quickfix, so you have to use one of the workarounds mentioned at
http://khsw.blogspot.com/2004/09/bug-in-aspnet-validator_07.html

Kind regards

Ken Cox said:
Hi Neil,

Looks like a bug... I couldn't make it work either.

I'll pass it along to a contact at MS to see what they say.

Ken
MVP [ASP.NET]

Blibo Baggins said:
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 ---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top