我创建“像应用程序一样的论坛”,我有文本框,用户可以在启动线程时输入用逗号分隔的标签。现在我想通知用户该标签尚未存在于数据库中,因此如果他输入新标签,则没有关注者,但如果他愿意,仍允许他输入标签。
到目前为止,这是我的代码:
<span>
Tags
</span>
<asp:TextBox ID="txtTags"
Width="70%"
runat="server">
</asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="TagsAutoComplete"
runat="server"
TargetControlID="txtTags"
MinimumPrefixLength="1"
CompletionInterval="3"
EnableCaching="true"
CompletionSetCount="10"
UseContextKey="True"
ServiceMethod="GetCompletionList"
DelimiterCharacters=",">
</ajaxToolkit:AutoCompleteExtender>
<ajaxToolkit:TextBoxWatermarkExtender
ID="txtTagsWatermark"
runat="server"
WatermarkCssClass="text-watermark"
TargetControlID="txtTags"
WatermarkText="Please enter tags sparated by
comma(,).You must enter at least one tag.">
</ajaxToolkit:TextBoxWatermarkExtender>
代码隐藏方法:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
using (ProblemClassesDataContext context = new ProblemClassesDataContext())
{
var tags = (from tag in context.Tags where tag.Title.StartsWith(prefixText) select tag.Title).Take(count);
return tags.ToArray();
}
}
答案 0 :(得分:0)
我使用Yuriy建议的解决方案。