views:

337

answers:

3

Hi,

I have a custom validator attached to a textbox control as follows

<td align="center" width="10px">
  <asp:CustomValidator ID="validateDateText" ControlToValidate="dateTextBox" 
       runat="server" OnServerValidate="ValidateDate" 
       ClientValidationFunction="Validate_Date" EnableClientScript="true" 
       Width="10px" CssClass="errortext" Text="*" Font-Size="Medium" Font-Bold="true" />
</td>
<td align="center" width="80px">
  <asp:Textbox ID="dateTextBox" MaxLength="100" runat="server"  
       CssClass="dateselectortextbox" style="margin-right: 3px;" />
</td>

When I click a button on the page with causesvalidation="true" the client script fires and the validation summary reflects the error message and the validator shows the *

However when I click out of the textbox only the * is displayed by the validator the validationsummary is not updated

The client side validation is working as the serverside code does not get called im just trying to work out why the validationsummary does not get updated on the onblur event

Any ideas?

EDIT:

The ErrorMessage is set in the codebehind for the validator

I have added the EnableClientScript to my validationsummary

I have added ValidationGroup to my validationsummary, customvalidator, textbox and button, but still the validation summary updates for the button click but not the textbox onblur event

A: 

You need to set dateTextBox.ValidationGroup, validateDateText.ValidationGroup and yourValidationSummary.ValidationGroup to the same value.

See http://msmvps.com/blogs/brianmadsen/pages/ASP.Net-2.0-_2D00_-How-to-use-the-new-validation-features_2C00_-part-1.aspx.

Ian Kemp
A: 

I think you might want to use ErrorMessage ="Some informative error message" inside your CustomValidator. You also need set ValidationGroup ="SomeGroupName" for CustomValidator ,ValidationSummary control and also the control which is causing postback.

Neil
+2  A: 

You definitely need to use the errormessage="xyz" for the message to show in the validation summary. The validation group shouldn't matter unless you have more than one group of controls you're validating.

Here is a link to another post that may help you with getting the validation summary to update after the onblur.

Ken
Thanks Ken, the link you posted enlightened me on the existence of the ValidationSummaryOnSubmit() function that I added to the onblur event and now all works as it should.
Adam Fox
Thanks (and an up-vote) also to Partario (the OP on that link). I hadn't heard of that method either until I read that post a while back.
Ken