1

我有一个转发器控件 rptbrand,其中有一个文本框 txtMultiBrand,并且在每次重复单击 btnAddBrand 按钮后,我想验证文本框中的唯一条目,这是我的 aspx 代码

<table width="100%">
    <asp:Repeater ID="rptBrand" runat="server" OnItemDataBound="rptBrandDetail_ItemDataBound">
        <ItemTemplate>
            <tr>
                <td align="right" `enter code here`width="150">
                    Brand<asp:Label ID="lblBrandNum" runat="server"></asp:Label>
                    <span class="msgred">*</span> :
                </td>
                <td align="left">
                    <table width="100%">
                        <tr>
                            <td align="left" width="20%">
                                <asp:TextBox ID="txtMultiBrand" CssClass="imageSearch" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ValidationGroup="VGrpMultiSave"
                                    ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
                                    SetFocusOnError="True"></asp:RequiredFieldValidator>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ValidationGroup="VGrpSave"
                                    ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
                                    SetFocusOnError="True"></asp:RequiredFieldValidator>
                            </td>
                            <td align="left">
                                <asp:ImageButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="CmdDelete"
                                    CommandArgument='<%# Eval("SrNo") %>' ToolTip="Delete" ImageUrl="images/b_drop.png"
                                    OnCommand="rptBrand_Command" Width="16" Height="16" OnClientClick="javascript:return confirm('Are you sure you want to remove brand?')" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </ItemTemplate>
    </asp:Repeater>
    <tr>
        <td align="right" width="150">
        </td>
        <td>
            <asp:Button ID="btnAddBrand" runat="server" Text="Add more" ValidationGroup="VGrpMultiSave"
                OnClick="btnAddBrand_Click" />
            <asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
                ShowMessageBox="True" ShowSummary="False" ValidationGroup="VGrpMultiSave" />
        </td>
    </tr>
</table>  
4

1 回答 1

0

使用 jQuery:

这是工作

检查以下链接:

http://jsfiddle.net/NtF7h/

  $(function () {
        $("#<%=btnAddBrand.ClientID%>").on("click", function (event) {
            var valueArray = new Array(); ;
            $("input[id*='txtMultiBrand']").each(function (index) {
                if ($.inArray($(this).val(), valueArray) == -1) {
                    valueArray[index] = $(this).val();
                }
                else {
                    alert("Duplicate Entry Found.");
                    event.preventDefault();
                    return false;
                }
            });
        });
    });
于 2012-08-23T13:50:02.737 回答