Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
ValidationSummary displays duplicate messages.
I'm using Textbox control inside Gridview , I have used RequiredFieldValidator for that TextBox.
If in Gridview control with more then 2 row and all Textboxs are empty then "ValidationSummary displays duplicate messages".

I want to display single message on ValidationSummary. If my all textboxs are empty then alos.

Please help me. Thanks in advance.

-Siddhesh
Posted
Updated 10-Nov-13 18:12pm
v3
Comments
JoCodes 18-Oct-13 13:58pm    
gridview inside textbox??? Can you post your code to the question?
Vishal Pand3y 20-Oct-13 13:16pm    
How is it Possible O.o

1 solution

XML
Use CustomValidator in place of RequiredFieldValidator so no require to use of ValidationSummary control

Pl follow below code for use requirement.


-----------------------------------------------------------------------------------
<head runat="server">
    <title>Untitled Page</title>

    <script src="../Script/jquery-1.6.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        function CheckValidGrid(source, args)
        {
            var fire =true;
            for(var i=1;i<$("#grddata tr").length;i++)
            {
                if($.trim($("#grddata tr:eq("+i+") input:[id*='txtCategoryName']").val())=="")
                {
                    fire =false;
                    break;
                }
            }
            if(!fire)
            {
                args.IsValid = false;
                alert("Please enter value for all new category name");
            }
            else
            {
                args.IsValid = true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
        </asp:SqlDataSource>
        <asp:GridView ID="grddata" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                <asp:TemplateField HeaderText="New Category Name">
                    <ItemTemplate>
                        <asp:TextBox ID="txtCategoryName" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:CustomValidator ID="cstValidate" ClientValidationFunction="CheckValidGrid" runat="server"></asp:CustomValidator>
    </div>
    <div>
        <asp:Button ID="btnsave" runat="server" Text="Save" />
    </div><pre><pre lang="HTML"></pre></pre>
    </form>
</body>
</html>
 
Share this answer
 
Comments
Rahul_Pandit 11-Nov-13 7:43am    
provide controltovalidate=txtCategoryName in custom validator

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900