0
我有一個接受用戶輸入的文本框。我需要比較用戶的輸入和來自數據庫中4個不同表格的列聯合的值。一旦用戶輸入與數據庫中存儲的公司名稱相匹配的公司名稱並警告用戶,標籤應該顯示。如何在輸入輸入時檢查用戶的輸入並將其與數據庫中的值進行比較?
<tr>
<td>Company Name:</td>
<td>
<telerik:RadTextBox ID="txtCompanyName" runat="server" Width="200px" OnTextChanged="txtCompanyName_TextChanged" >
</telerik:RadTextBox>
<%--to display warning if company name exists--%>
</td>
<td>
<asp:RequiredFieldValidator ID="rfCompanyName" runat="server"
ErrorMessage="* Company Name Required" ValidationGroup="LeadValidation"
ControlToValidate="txtCompanyName"
Display="Dynamic" ForeColor="Red"/>
</td>
<td>
<asp:Label ID="lblCompanyNameExists" Text="Warning: Company Name already Exists"
ForeColor="Orange" runat="server" Visible="false" />
</td>
</tr>
目前我使用的OnTextChanged
比較值,但是當按下一個按鈕,這只是驗證。
protected void txtCompanyName_TextChanged(object sender, EventArgs e)
{
lblCompanyNameExists.Visible = false;
List<string> CurrentCompNames = new LeadsManager().GetCompanyNames();
foreach (string companyName in CurrentCompNames)
{
if (companyName == txtCompanyName.Text)
{
lblCompanyNameExists.Visible = true;
//return;
}
}
}
我該從哪裏出發?