【问题标题】:force user select from autocomplete强制用户从自动完成中选择
【发布时间】:2012-03-16 14:46:54
【问题描述】:

我是 asp.net 的初学者。我现在面临一个问题。如何强制用户从 ajax 控制工具包自动完成中选择选项? 这是我的示例代码

<cus:cusTextBox ID="txtCMemberID" runat="server" Action="Edit"
    CssClass="inputTextM" OnTextChanged="txtCMemberID_TextChanged"
    AutoPostBack="True"></cus:cusTextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
    ServicePath="~/Module/Common/autoComplete/acLewreMember.asmx"
    MinimumPrefixLength="1" ServiceMethod="GetSuggestedStrings"
    TargetControlID="txtCMemberID" CompletionInterval="10"
    CompletionSetCount="3" EnableCaching="true"
    CompletionListCssClass="completionListElement"
    CompletionListItemCssClass="listItem"
    CompletionListHighlightedItemCssClass="highlightedListItem"
    FirstRowSelected="True"
    ShowOnlyCurrentWordInCompletionListItem="True">
</asp:AutoCompleteExtender>

如您所见,文本框是一个自定义控件。这是强制用户从自动完成中选择选项的任何方式吗?请也给我一个示例代码。谢谢

【问题讨论】:

    标签: asp.net ajax autocomplete


    【解决方案1】:

    ASP.NET 包含一个称为验证器的有用功能。

    <asp:TextBox ID="TextBox2" ValidationGroup="Group2" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="*Required" ValidationGroup="Group2"
    ControlToValidate="TextBox2" runat="server" />
    <asp:Button ID="Button2" Text="Validate Group2"
    ValidationGroup="Group2" runat="server" />
    

    这里是msdn的资源链接:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx

    我不确定这些如何与自定义控件一起使用,因为我在 asp 方面相对较新。他们还有一个自定义验证器,它可能更适合您的目的,但就像我说的那样。我不确切知道。

    注意:如果客户端使用的是旧浏览器,这将不起作用,因此您还需要在服务器上检查此字段是否为空:

    if (Page.IsValid)
    {
         //stuff to do in your event handler
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多