views:

30

answers:

2

below is the code and when i select a wrong filetype i get instant red "*" but i dont see the validation summary and there is a buton("upload") and when i click on it than i get the validation summary error message.

my question is: why validation summary is not displaying when i select the wrong file type?

<asp:ValidationSummary ForeColor="DarkRed" 
 ID="ValidationSummary1" runat="server" ShowMessageBox="False"
 HeaderText="To save this page, the following required fields must be completed:" ShowSummary="true" />

  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" EnableClientScript="true" runat="server" ControlToValidate="fUpload"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.rtf|.RTF|.Rtf|.xls|.XLS|.Xls)$" Text="*"
ErrorMessage="Invalid file type" SetFocusOnError="true" Display="Dynamic">/></asp:RegularExpressionValidator> 
A: 

The ValidationSummary is displayed when you try to submit the form (click the submit button), and not exactly after you fill in the form fields.

If you have Display="Dynamic" on your validator, like you have, the only thing you'll instantly get is the message in your validator's Text property. So, if you want to instantly get the error message, you'll have to change Text="*" to Text="Invalid file type".

Dan Dumitru
+1  A: 

As your RegularExpressionValidator has EnableClientScript="true", it will cause a client side validation of the control.

A ValidationSummary control, even though it may also be set to EnableClientScript="true" has to validate all controls with its own group, so will not display the error message in the same way. This is by design, so will only work once the form has been submitted.

To stop the '*' from displaying instantly, you can either set the control to Display="None" or change to EnableClientScript="false"

Tim B James