-1

I have been trying to find the solution for this my self but im on my wits end with this problem.

What happen is, I am not able to Save new entry data because of the validator. if i set the CausesValidation = false or delete all the validation, i am able to save the data. on the other hand, currently, it won't show any validation error message when the value is blank and the save button does not work at all. i tried to use breakpoint if the edit code in c# hits that point or not and apparently it does not go there as it is supposed to do.

The error happen suddenly while i change some of the text and formatting of the grid, everything was functioning as normal before. this is the second time that this has occur as with the first time, it somehow fixed it self and i was able to run it again. as i want to make a reliable website, i would like to know how i can fix this issue so it does not occur again.

<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover table-striped" DataKeyNames="ParticipantID" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="PRCData"  OnRowCommand="GridView1_RowCommand" AllowPaging="True" OnRowUpdating="GridView1_RowUpdating" onpageindexchanging="gw_PageIndexChanging" BorderStyle="Solid" Font-Bold="False" GridLines="Vertical" PageSize="15">
                    <EmptyDataTemplate>
                        <table class="table table-hover table-striped" border="1" style="border-collapse: collapse;">
                            <tr>
                                <th scope="col">First name</th>
                                <th scope="col">Surname</th>
                                <th scope="col">Gender</th>
                                <th scope="col">Year level</th>
                                <th scope="col">Books read</th>
                                <th scope="col"></th>

                            </tr>
                            <tr>
                                <td colspan="8" align="center">No record found</td>
                            </tr>
                        </table>
                    </EmptyDataTemplate>

                    <Columns>


                        <asp:BoundField DataField="ParticipantID" HeaderText="ParticipantID" InsertVisible="False" ReadOnly="true" SortExpression="ParticipantID" Visible="False" />

                        <asp:TemplateField HeaderText="First name">
                            <itemstyle Width="20%" VerticalAlign="Middle"/> 
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Eval("FirstName") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                               <div> <asp:TextBox ID="FirstName" runat="server" Width="100%" MaxLength="50" DataSourceID="PRCData" DataTextField="FirstName" DataValueField="FirstName" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator Display="Dynamic" runat="server" ControlToValidate="FirstName"
                CssClass="text-danger" ErrorMessage="The first name field is required." ><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The first name field is required.</asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator  CssClass="text-danger" Display="Dynamic" ControlToValidate="FirstName" runat="server" ValidationExpression="^[a-zA-Z''-'\s]{1,50}$" ErrorMessage="Not a valid first name."><span class="glyphicon glyphicon-exclamation-sign"  aria-hidden="true"></span> Not a valid first name.</asp:RegularExpressionValidator></div>
                            </EditItemTemplate>
                            <FooterTemplate>
                               <div> <asp:TextBox ID="addFirstName" runat="server"  Width="100%" MaxLength="50" DataSourceID="PRCData" DataTextField="FirstName" DataValueField="FirstName" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator Display="Dynamic" runat="server" ErrorMessage="The first name field is required." ControlToValidate="addFirstName"
                CssClass="text-danger"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The first name field is required.</asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator  Display="Dynamic" CssClass="text-danger" ControlToValidate="addFirstName" runat="server" ValidationExpression="^[a-zA-Z''-'\s]{1,50}$"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Not a valid first name.</asp:RegularExpressionValidator></div>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Surname">
                            <itemstyle Width="20%" VerticalAlign="Middle"/> 
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Eval("Surname") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                              <div>  <asp:TextBox ID="Surname" runat="server" Width="100%" MaxLength="50"  DataSourceID="PRCData" DataTextField="Surname" DataValueField="Surname" Text='<%# Bind("Surname") %>'></asp:TextBox></div><div>
                                <asp:RequiredFieldValidator ErrorMessage="The surname field is required." Display="Dynamic" runat="server" ControlToValidate="Surname"
                CssClass="text-danger"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The surname field is required.</asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator Display="Dynamic"  CssClass="text-danger" ControlToValidate="Surname" runat="server" ValidationExpression="^[a-zA-Z''-'\s]{1,50}$"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Not a valid surname.</asp:RegularExpressionValidator></div>
                            </EditItemTemplate>
                            <FooterTemplate>
                              <div>  <asp:TextBox ID="addSurname" runat="server" Width="100%" MaxLength="50"  DataSourceID="PRCData" DataTextField="Surname" DataValueField="Surname" Text='<%# Bind("Surname") %>'></asp:TextBox></div><div>
                                  <asp:RequiredFieldValidator ErrorMessage="The surname field is required." Display="Dynamic" runat="server" ControlToValidate="addSurname"
                CssClass="text-danger" ><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The surname field is required.</asp:RequiredFieldValidator>
          <asp:RegularExpressionValidator Display="Dynamic"  CssClass="text-danger" ControlToValidate="addSurname" runat="server" ValidationExpression="^[a-zA-Z''-'\s]{1,50}$"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> Not a valid surname.</asp:RegularExpressionValidator></div>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Age">
                            <itemstyle Width="5%" VerticalAlign="Middle"/> 
                            <EditItemTemplate>
                              <div>  <asp:TextBox ID="TextBox1" ErrorMessage="The age field is required." Width="100%" TextMode="Number" runat="server" min="0" max="20" step="1" Text='<%# Bind("Age") %>'></asp:TextBox></div><div>
                                  <asp:RequiredFieldValidator Display="Dynamic" runat="server" ControlToValidate="TextBox1" 
                CssClass="text-danger" ><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The age field is required.</asp:RequiredFieldValidator></div>
                            </EditItemTemplate>
                            <FooterTemplate>
                             <div>   <asp:TextBox ID="addAge" Width="100%" TextMode="Number" runat="server" min="0" max="20" step="1" Text=0 ></asp:TextBox></div><div>
                                <asp:RequiredFieldValidator ErrorMessage="The age field is required." Display="Dynamic" runat="server" ControlToValidate="addAge"
                CssClass="text-danger"  ><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> The age field is required.</asp:RequiredFieldValidator></div>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label7" runat="server" Text='<%# Bind("Age") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Gender">
                               <itemstyle Width="5%" VerticalAlign="Middle"/> 
                            <EditItemTemplate>
                                <asp:DropDownList Width="100%" ID="DropDownList1" runat="server">
                                    <asp:ListItem>Male</asp:ListItem>
                                    <asp:ListItem>Female</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1"  runat="server" Text='<%# Bind("Gender") %>'></asp:Label>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList Width="100%" ID="DropDownList2" runat="server">
                                    <asp:ListItem>Male</asp:ListItem>
                                    <asp:ListItem>Female</asp:ListItem>
                                </asp:DropDownList>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Year level">
                               <itemstyle Width="7.5%" VerticalAlign="Middle"/> 
                            <EditItemTemplate>
                                <asp:DropDownList  Width="100%" ID="YearLevel" runat="server" Text='<%# Bind("YearLevel") %>'>
                                    <asp:ListItem>Prep</asp:ListItem>
                                    <asp:ListItem>Year 1</asp:ListItem>
                                    <asp:ListItem>Year 2</asp:ListItem>
                                    <asp:ListItem>Year 3</asp:ListItem>
                                    <asp:ListItem>Year 4</asp:ListItem>
                                    <asp:ListItem>Year 5</asp:ListItem>
                                    <asp:ListItem>Year 6</asp:ListItem>
                                    <asp:ListItem>Year 7</asp:ListItem>
                                    <asp:ListItem>Year 8</asp:ListItem>
                                    <asp:ListItem>Year 9</asp:ListItem>
                                    <asp:ListItem>Other</asp:ListItem>
                                    <asp:ListItem>Special</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="addYearLevel" runat="server" Text='<%# Bind("YearLevel") %>'></asp:Label>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList Width="100%" ID="addYearLevel" runat="server">
                                    <asp:ListItem>Prep</asp:ListItem>
                                    <asp:ListItem>Year 1</asp:ListItem>
                                    <asp:ListItem>Year 2</asp:ListItem>
                                    <asp:ListItem>Year 3</asp:ListItem>
                                    <asp:ListItem>Year 4</asp:ListItem>
                                    <asp:ListItem>Year 5</asp:ListItem>
                                    <asp:ListItem>Year 6</asp:ListItem>
                                    <asp:ListItem>Year 7</asp:ListItem>
                                    <asp:ListItem>Year 8</asp:ListItem>
                                    <asp:ListItem>Year 9</asp:ListItem>
                                    <asp:ListItem>Other</asp:ListItem>
                                    <asp:ListItem>Special</asp:ListItem>
                                </asp:DropDownList>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Books read">
                            <itemstyle Width="5%" VerticalAlign="Middle"/> 
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("BooksRead") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                               <div> <asp:TextBox ID="BooksRead" Width="100%" TextMode="Number" min="0" max="20" runat="server" DataSourceID="PRCData" DataTextField="BooksRead" DataValueField="BooksRead" Text='<%# Bind("BooksRead") %>'></asp:TextBox></div>

                            </EditItemTemplate>
                            <FooterTemplate>
                             <div>   <asp:TextBox ID="addBooksRead"  Width="100%" TextMode="Number" min="0" max="20" runat="server" DataSourceID="PRCData" DataTextField="BooksRead" DataValueField="BooksRead" Text=0></asp:TextBox></div>

                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="School name (if applicable)">
                            <itemstyle Width="30%" VerticalAlign="Middle"/> 
                            <ItemTemplate>
                                <asp:Label ID="SchN" runat="server" Text='<%# Eval("SchoolName") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="SchoolName" runat="server" Width="100%" MaxLength="30" DataSourceID="PRCData" DataTextField="Surname" DataValueField="SchoolName" Text='<%# Bind("SchoolName") %>'></asp:TextBox>

                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="addSchoolName" runat="server" Width="100%" MaxLength="30" DataSourceID="PRCData" DataTextField="addSchoolName" DataValueField="addSchoolName" Text=""></asp:TextBox>

                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                               <itemstyle Width="7.5%" VerticalAlign="Middle" HorizontalAlign="right"/> 
                            <ItemTemplate>
                                <asp:LinkButton runat="server" ButtonType="Button" Width="100%" CommandName="Edit" ControlStyle-CssClass="btn btn-primary " HeaderText="" causesValidation="False" ShowHeader="false"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</asp:LinkButton>
                                <asp:LinkButton runat="server" ButtonType="Button" Width="100%" CommandName="Delete" ControlStyle-CssClass="btn btn-primary" HeaderText="" causesValidation="False" ShowHeader="false" OnClientClick="return ConfirmOnDelete();"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</asp:LinkButton>
                               <script type="text/javascript">    
                                       function ConfirmOnDelete() {
                                        if (confirm("Do you really want to delete?") == true)
                                            return true;
                                        else
                                            return false;
                                       }
                                    </script>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton runat="server" ButtonType="Button" Width="100%" CommandName="Update" ControlStyle-CssClass="btn btn-primary" HeaderText="" ShowHeader="false"  ><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save</asp:LinkButton>


                            <asp:LinkButton runat="server" ButtonType="Button" Width="100%" CausesValidation="False" CommandName="Cancel" ControlStyle-CssClass="btn btn-primary" ><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Cancel</asp:LinkButton>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:LinkButton ButtonType="Button" runat="server" Width="100%" CommandName="ADD" ControlStyle-CssClass="btn btn-primary" HeaderText=""  ShowHeader="false"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Save</asp:LinkButton>
                                <asp:LinkButton ButtonType="Button" runat="server" Width="100%" ControlStyle-CssClass="btn btn-primary" CommandName="Cancel" causesValidation="False"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Cancel</asp:LinkButton>
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="StatusID" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="StatusID" runat="server" Text='<%# Bind("StatusID") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="StatusID" runat="server" Text='<%# Bind("StatusID") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                      <FooterStyle CssClass="GridViewEditRow" />
            <HeaderStyle CssClass ="headerStyle" BackColor="PaleTurquoise" BorderStyle="Groove" Font-Bold="True" Font-Size="Larger" />
             <EditRowStyle CssClass="GridViewEditRow"  />
                    <PagerStyle CssClass="gvwCasesPager"/>
                </asp:GridView>

Thank you in advance for your time and help.

Edit 1: The ScriptManager is located on the site.master file and linked with this page

Edit 2: Tried to set the Display for validation to none and use ValidationSummary instead, also does not work

3 Answers3

0

First Add ScriptManger in your aspx page it will resolve your validation error

Muhafil Saiyed
  • 230
  • 1
  • 20
  • And you are using you are using site.master as master page of your grid page right ? – Muhafil Saiyed Apr 05 '16 at 05:36
  • oh Okay ! than let me look at your code one more time .. in my case i was getting same error and it will resolve when i define script manager on grid page ... – Muhafil Saiyed Apr 05 '16 at 05:39
  • I tried put ScriptManagerProxy just in case but nope, does not work still :/ Like i said, the page was working fine before until suddenly while i change the style, it suddenly went kaput. – Christofer Fabian Widjaja Apr 05 '16 at 05:41
0

I do not see that you have set the InitialValue attribute of the RequiredFieldValidator.

Red_Phoenix
  • 482
  • 6
  • 22
-1

After Looking into more detail, the problem was The Ajax on Client side did not load, i have managed to fix this by referring to this link.

Thanks for the help guys!

Community
  • 1
  • 1