2016-06-13 12 views
0

私はasp.net Listviewを持っており、EditItemTemplateの編集操作のためにRequiredFieldValidatorを追加しました。asp.net - Listbox - InsertItemTemplate RequiredFieldValidator

「編集」ボタンをクリックし、空のCustomerNameTextBoxでデータを保存しようとすると「あなたの名前を入力してください!」というエラーが表示されます。
これは

<%@ Page Language="C#" UnobtrusiveValidationMode="None" AutoEventWireup="true" CodeBehind="frmMain.aspx.cs" Inherits="DB_mit_GridView.frmMain" %> 

<EditItemTemplate> 
    <tr style=""> 
     <td> 
      <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /> 
      <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> 
     </td> 
     <td> 
      <asp:Label ID="CustomerIDLabel1" runat="server" Text='<%# Eval("CustomerID") %>' /> 
     </td> 
     <td> 
      <asp:TextBox ID="CustomerNameTextBox" runat="server" Text='<%# Bind("CustomerName") %>' /> 
      <%-- CustomerNameTextBox must not be empty when editing an existing record 
      <asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="CustomerNameTextBox" errormessage="Please enter your name!" /> 
     </td> 

OKですしかし、私は、私は新しいレコードを挿入すると既存のレコードを編集するだけでなく、空CustomerNameTextBoxをチェックします。
だから私はInsertItemTemplateでの挿入操作のためのRequiredFieldValidatorを追加します。

<InsertItemTemplate> 
    <tr style=""> 
     <td> 
      <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> 
      <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> 
     </td> 
     <td> 
      <asp:TextBox ID="CustomerIDTextBox" runat="server" Text='<%# Bind("CustomerID") %>' /> 
     </td> 
     <td> 
      <asp:TextBox ID="CustomerNameTextBox" runat="server" Text='<%# Bind("CustomerName") %>' /> 
      <%-- CustomerNameTextBox must not be empty when insertig a new record 
      <asp:RequiredFieldValidator runat="server" id="reqName2" controltovalidate="CustomerNameTextBox" errormessage="Please enter your name!" /> 
     </td      

しかし、すぐに、私はInsertItemTemplateにのRequiredFieldValidatorを追加すると、私はメッセージを取得する「あなたの名前を入力してください!」そのページの開始直後。
「挿入」ボタンをクリックしていません。メッセージはクリックせずに表示されます。

したがって、編集または挿入するときに特定のテキストボックスが空でないことを確認するにはどうすればよいですか?私はその後、検証グループは、ポストバックを使用する正しく記事をundertstoond場合

答えて

関連する問題