I am facing a problem while making use of ValidationSummaryControl and CustomValidator.
I have set the ShowMessageBox=true and ShowSummary=false for Summary control.So i expect it to show a messagebox when my custom validation fails.For testing purpose in my servervalidate event handler of CustomValidator i made the ServerValidateEventArgs.IsValid to false.So i expect the validation to fail and show a messagebox,everytime i enter some valuse in my text box and click on the button .But the messagebox is not displayed and to add to my confusion if i set the ShowMessageBox=false and ShowSummary=true the validation summary report is shown properly.
So how can i display the messagebox if my customvalidation fails.is this a bug with controls or am i missing anything here?
I don’t want to make this posting bulky,so will post the code if itz of some use.
Someone pls help me out to fix this problem.
Yep, this is weird, and the ridiculous answer to the question is; the function that displays the alert() isn’t called if you post the form using Enter in a textbox for example - if you click the Submit button, then it’s working
(Must be some way to change the page to call Page_ClientValidate() on onsubmit for the form)
If this explanation doesn’t apply to your problem, check that EnableClientScript is set to true
I noticed this: “…in my servervalidate event handler…”
Don’t you mean ClientValidationFunction ?
It’s a bit difficult to pop up a message box from the server
thanx for the reply.
But i am not using any client side validation for custom control.I am using the ServerValidate event(As per MSDN The ServerValidate event is raised when validation is performed on the server) of custom validator to perform checking against database and for testing purpose(to show messagebox) am setting IsValid to false all the time so that Messagebox of valdationsummary control to pop up.
So my question is that if validationsummary can show a summary report for the validations done in ServerValidate event then y it is not showing messagebox properly even though Isvalid is set to false.
is my question clear enough?
if not i will post more code to elaborate on this problem
Could you post a little code?
<form id=“CustomValidator” method=“post” runat=“server”>
<asp:TextBox id=“TextBox1” runat=“server”></asp:TextBox>
<asp:Button id=“btnSubmit” runat=“server” Text=“Submit”></asp:Button>
<asp:CustomValidator id=“CustomValidator1” ControlToValidate=“TextBox1” Display=“None” Runat=“server” ErrorMessage=“Enter ‘SitePoint’ to be valid” runat=“server”></asp:CustomValidator>
<asp:ValidationSummary ID=“ValidationSummary” Runat=“server” ShowMessageBox=“True” ShowSummary=“false” DisplayMode=BulletList ></asp:ValidationSummary>
<asp:Label ID=“lblStatus” Runat=“server”></asp:Label>
//Server Validate event mapping
this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.ValidateText);
//Event Handler function
private void ValidateText(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
args.IsValid=false; //done to make validation false
lblStatus.Text="Not Valid at ServerValidateEvent ";
This is the code which causes the problem.Is this the problem with my code.
If i change the aspx file to ShowMessageBox=“False” and ShowSummary=“true”,then validation summary is shown properly.But messagebox never comes out:(
Have to modify my previous statement:
“It’s a bit difficult to pop up a message box from the server”
However, you have to add that code manually
I modified the EnableClientScript to true.
<asp:ValidationSummary ID=“ValidationSummary” Runat=“server” EnableClientScript=True ShowMessageBox=“True” ShowSummary=“false” DisplayMode=“BulletList”></asp:ValidationSummary>
But still it does’nt show any messagebox.
Can nayone figure out whether there is any problem with my usage of validation controls?
Pls note that if i replace CustomValidator with any other validation control it shows the messagebox.
' On the server:
Private Sub Test(ByVal sender As Object, ByVal args As ServerValidateEventArgs) Handles myControl.ServerValidate
If True = False Then
args.IsValid = True
args.IsValid = False
// On the client:
function Test(sender, args)
if (true == false)
args.IsValid = true;
args.IsValid = false;
…and in the aspx page you specify:
<asp:customvalidator id=“myControl” … ClientValidationFunction=“Test”>
that solves the issue of Messagebox not getting displayed.
But what i would like to see is to do validation against a database entry.So as far as i know the validation part has to be done in the server in this case.If i EnableClientScript and set the ClienValidateFunction then the validation will be done in the client side script and at that point database validation is not possible.
So my aim to do the validation in the Server from where i will set the IsValid and i expect the messagebox to pop up depending on IsValid value.
Pls not that I am able to show the summary of validations as text after doing the validations in the server,but messagebox is reluctant to come up:)
thanx jofa for the replies
Originally posted by ngmtech
… validation will be done in the client side script and at that point database validation is not possible.
Can’t you make a little xmlhttp request in the client side script?
it took me a while to undesrtand what xmlhttp request is all about(Since am new to this world:))
ok i agree that i can make use of xmlhttp request.
but what really confuses me is y the server validation is not properly handled in validation summary.
anyway leave it buddies and thanx for the suggestions
Take a look at WebUIValidation.js in C:\Inetpub\wwwroot\aspnet_client\system_web\version_number and you will see why the alert() is shown only when the submit button is clicked, and not when you reload the page (after server validation)