Hi Moondday,
I've tested using a ValidateSummary according to your description. And
found that bydefault the ValidateSummary won't show message if the client
validators are enabled because the validators will pop up the error message
first(client validation). However, when disable those validators by uncheck
the checkbox, the page will be postedback and the ValidateSummary will
display serverside validation's validate result message. To avoid this , I
think we can disable the ValidateSummary at serverside(in Page_load since
the page's valiate() method is not called in Page_Load()) when the page is
posted back rather than at clientside. For example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
vsMain.Enabled = chkEnableValidation.Checked
End Sub
'vsMain is the validateSummary control
And below is the modified test page's source:
===================aspx page=======================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Validators</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function setValidation(val)
{
ValidatorEnable(document.getElementById("rfvOne"), val);
ValidatorEnable(document.getElementById("rfvTwo"), val);
ValidatorEnable(document.getElementById("rfvThree"), val);
ValidatorEnable(document.getElementById("rfvFour"), val);
}
</script>
</HEAD>
<body
onload="setValidation(document.getElementById('chkEnableValidation').checked
)">
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:ValidationSummary id="vsMain"
runat="server"></asp:ValidationSummary></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtOne" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvOne" runat="server"
ErrorMessage="txtOne is empty!"
ControlToValidate="txtOne"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtTwo" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvTwo" runat="server"
ErrorMessage="txtTwo is empty!"
ControlToValidate="txtTwo"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtThree" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvThree" runat="server"
ErrorMessage="txtThree is empty!"
ControlToValidate="txtThree"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtFour" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvFour" runat="server"
ErrorMessage="txtFour is empty!"
ControlToValidate="txtFour"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
EnableValidation:<INPUT type="checkbox" id="chkEnableValidation"
CHECKED onclick="setValidation(this.checked)"
runat="server">
<asp:Button id="btnPost" runat="server" Text="PostBack"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</HTML>
===============code behind page class===============
Public Class validator
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 txtOne As System.Web.UI.WebControls.TextBox
Protected WithEvents rfvOne As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtTwo As System.Web.UI.WebControls.TextBox
Protected WithEvents rfvTwo As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtThree As System.Web.UI.WebControls.TextBox
Protected WithEvents rfvThree As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtFour As System.Web.UI.WebControls.TextBox
Protected WithEvents rfvFour As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents btnPost As System.Web.UI.WebControls.Button
Protected WithEvents chkEnableValidation As
System.Web.UI.HtmlControls.HtmlInputCheckBox
Protected WithEvents vsMain 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
vsMain.Enabled = chkEnableValidation.Checked
End Sub
Private Sub btnPost_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPost.Click
Response.Write("<br>Page is posted back at: " +
DateTime.Now.ToLongTimeString())
Response.Write(Page.IsValid)
End Sub
End Class
=========================================
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx