私はこの自己の解決策を見つけようとしていますが、私の知恵はこの問題で終わりです。asp.net Validatorがエラーメッセージを表示せず、リンクボタンがグリッドビュー上で保存されていません
バリデータのために新しいエントリデータを保存できません。私はCausesValidation = falseを設定するか、すべての検証を削除すると、私はデータを保存することができます。一方、値が空白で保存ボタンがまったく機能しない場合は、現在、検証エラーメッセージは表示されません。私はブレークポイントを使用しようとしましたが、C#のエディットコードがそのポイントに当たってもいなくても、明らかにそれが実行されるはずです。
グリッドのテキストと書式の一部を変更すると、突然エラーが発生します。以前はすべて正常だったようです。これは初めての場合と同じように発生した2回目のことですが、何とかそれを自己修正し、再び実行することができました。私は信頼できるウェブサイトを作りたいので、私はこの問題をどのように修正して再び起こるのか知りたいと思います。
<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>
ご協力いただきありがとうございます。
編集1: のScriptManagerがsite.masterファイル上に配置され、このページにリンクされて
編集2: ではなく、また
は動作しませんnoneに検証のための表示を設定し、にValidationSummaryを使用しようとしました問題がロードされなかったクライアント側でのAjaxた
スクリプトマネージャはsite.masterファイル –
にあります。あなたはグリッドページのマスターページとしてsite.masterを使用していますか? –
はい、それは正しいです –