?
Solved

Validation Summary not populated when validator is triggered

Posted on 2005-05-02
14
Medium Priority
?
578 Views
Last Modified: 2008-01-09
I have a web page with about 15 datagrids on it (don't ask). Each datagrid resides in it's own DIV and these divs can be shown/hidden based on the button pushed. All of this works.

The datagrids themselves are fully functional, and allow the user to add/edit/delete records. All of this works.

I am now trying to add validation controls. So far, I've only tried one. Here is the HTML for the FooterTemplate (where I add new records), minus some extraneous formatting:
<FooterTemplate>
  <asp:textbox id="add_SwitchQuantity" text='1' visible="false" width="25px" MaxLength="20" cssclass="DataGridInputControl" runat="server" />
  <asp:RequiredFieldValidator id="add_SwitchQuantityValidate" ControlToValidate="add_SwitchQuantity" ErrorText="You must add the quantity" Text="You must add the quantity" Display="Dynamic" Runat="server"></asp:RequiredFieldValidator>
</FooterTemplate>

I also have a validation summary control. I've tried putting this both at the bottom of the page, and in the same div as the datagrid. Neither works.
<asp:validationsummary id="ValidationSummary1" runat="server"></asp:validationsummary>

The validator itself IS firing -- the in-line text appears just fine. However, I would like to remove the in-line text, and use only the validation summary. Does anyone have any suggestions?

Thanks in advance for your help!
0
Comment
Question by:Jeff Certain
  • 7
  • 5
13 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 13914462
The RequiredFieldValidator doesn't have an "ErrorText" property, perhaps you mean "ErrorMessage"?  This may have just been a typo on your part and have nothing to do with what you are actually doing.

--Michael
0
 
LVL 39

Expert Comment

by:appari
ID: 13914956
try changing validationsummary control tag like this

<asp:validationsummary id="ValidationSummary1" ShowSummary="False" ShowMessageBox="True" runat="server"></asp:validationsummary>

and requirefieldvalidator tag to

<asp:RequiredFieldValidator id="add_SwitchQuantityValidate" ControlToValidate="add_SwitchQuantity" ErrorMessage="You must add the quantity" Text="*" Display="Dynamic" Runat="server"></asp:RequiredFieldValidator>


now on lostfocus of add_SwitchQuantity contorol a "*" is displayed and when you try to submit you should get a messagebox with the error "You must add the quantity"
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13918143
raterus,
You're right about the ErrorMessage. However, I got it right the first time I tried it, and it didn't work. The "ErrorText" typo was from the nth iteration.

appari,
I don't get the message box appearing, either when the textbox loses the focus, or when I submit the form.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:raterus
ID: 13918193
I think you just need to change Display="Dyanmic" to Display="None", just tried this, and only the validation summary showed the error, and I think this is what you want.
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13918230
Raterus,

The problem is that the validation summary does not show any errors, even though the inline error is shown. The operation of the summary should be independent of the operation of the inline validator...
0
 
LVL 33

Expert Comment

by:raterus
ID: 13918392
Just tried doing exactly what you were doing, added a validator/textbox to a footertemplate, and a validationsummary outside of the datagrid.  Everything worked like you want.  You aren't adding any of these validators dynamically are you?  Can you reproduce this problem on a smaller scale?
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13918459
The validators are being added in design time in the footertemplate.

And, unfortunately, I can't reproduce the error on a smaller scale. In fact, the MS exmaple (Datagrid9) that shows similar techniques works just fine.

I'm wondering if perhaps the DIV around the datagrid is causing problems? Back to the drawing board...
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13918929
I've created a fresh web form and put the datagrid with supporting code on the page. No other datagrids or extraneous controls. Still no luck. The RFV still fires, but the validation summary doesn't collect the error.
0
 
LVL 33

Expert Comment

by:raterus
ID: 13918939
Possible to post the code?
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13918980
raterus,
Yes... but it would be better zipped and e-mailed to you. As I'm sure you can understand, I'll want to create a SQL user for your temporary use, and I need to change the connection string info. Then I'll need to create a new solution that only contains the relevant code (otherwise, you'll have WAY too much to look at). The code-behind page has about 600 lines of code, and that's not counting the supporting code that is called externally.
{removed email address - raterus}
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13919128
Okay... should I post all the code here, then?
0
 
LVL 33

Accepted Solution

by:
raterus earned 2000 total points
ID: 13920715
If your page postbacks, you need to recheck the validation on the serverside in order to suppress any code that may execute, try this in the button.click event

Page.Validate()
If Page.IsValid Then
  'insert code you normally would run here
End If

The reason you have to do this is because validators are really server-side controls that happen to allow you to validate on the client-side.  Asp.net doesn't know what code you want ran/not ran when the page isn't valid, so it leaves this up to you using the Page.IsValid property.  I could see how if your page posted back, was invalid, but you never checked this how it may appear that the validation summary isn't being filled.

Does this help?
--Michael
0
 
LVL 24

Author Comment

by:Jeff Certain
ID: 13920768
Michael,
That pointed me on the right track. The real "gotcha" here was that the button that saved the new record was set to CausesValidation="false". I discovered this when I was trying to figure out why the server-side code was even running. After all, validators generate client-side script that runs if the user has javascript enabled. Once I fixed that oversight, everything mysteriously started working... <grin />

Thanks for all your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question