asp.net - Listbox - InsertItemTemplate RequiredFieldValidator

时间:2016-06-13 10:50:03

标签: asp.net listview requiredfieldvalidator

我有一个asp.net Listview,我在EditItemTemplate中为编辑操作添加了一个RequiredFieldValidator。

当我点击“编辑”按钮并尝试使用空的CustomerNameTextBox保存数据时,我收到错误“请输入您的姓名!”
这没关系

    % Unset trace flags on P2. 
    erlang:trace(P2Pid, false, [set_on_spawn, send, 'receive']),

    % We might lose trace events at this instant which were raised
    % by process P2 while un-setting the tracer on P2 and setting
    % it again.

    % Now set again trace flags on P2, directing the trace to 
    % a new tracer T2.
    erlang:trace(P2Pid, true, [set_on_spawn, send, 'receive', {tracer, T2Pid}]),

但是我不仅要在编辑现有记录时检查空CustomerNameTextBox,还要在插入新记录时检查。 所以我在InsertItemTemplate中为Insert操作添加了RequiredFieldValidator:

<%@ 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>

但是只要我将RequiredFieldValidator添加到InsertItemTemplate,我就会收到消息“请输入你的名字!”在页面开始后立即 我没有点击“插入”按钮 - 只显示消息而没有任何点击。

那么在编辑或插入时如何确保某些文本框不为空? (我没有代码)

1 个答案:

答案 0 :(得分:0)