Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView + ValidationSummary 1

Status
Not open for further replies.

JoeAtWork

Programmer
Jul 31, 2005
2,285
CA
In a GridView template field, I have a textbox in an ItemTemplate and Compare validator directly below it (checking that an integer was entered). Underneath the grid I have a ValidationSummary. If I enter a non-integer in the textbox, the ErrorMessage displays within the CompareValidator in the grid, instead of showing on the ValidationSummary. Here's my code:
Code:
<asp:TemplateField HeaderText="Qty">
    <ItemTemplate>
        <asp:TextBox Text='<%# Bind("Quantity") %>' onChange='EnableEntrySave()'
         Width="100%" ID="txtQuantity" runat="server">
        </asp:TextBox>
       <asp:CompareValidator ID="valQtyNumeric" runat="server" ControlToValidate="txtQuantity"
        Display="Dynamic" SetFocusOnError="true" Text="" ErrorMessage="Error: Qty must be a number!" Operator="DataTypeCheck" Type="Integer">
       </asp:CompareValidator>
    </ItemTemplate>
    <ItemStyle Width="10%" />
</asp:TemplateField>

And for the ValidationSummary:
Code:
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List"
        EnableViewState="False" Width="100%" />

 
What I usually do is add a Text property to each validation control so that it highlights which field needs to be entered but the ValidationSummary control actually shows the error message e.g.
Code:
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter TextBox1 Value" Text="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter TextBox2 Value" Text="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
OK, that sounds like a good idea.

But that doesn't solve my problem, which is the ErrorMessage is not displaying in the ValidationSummary. Rather, it is displaying in the CompareValidator (i.e. it is treating the ErrorMessage as if it was the Text).


 
Ultimately, I found the problem was that my submit button was disabled on form load. If I enabled it by default, the ValidationSummary worked.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top