我在我的代码中使用 ajax 组合框代替下拉列表,现在我想在客户端验证它。我选择使用 javascript 并使用以下代码来验证它:
function validateCombobox(){
var comboboxId = document.getElementById('<%=ComboBox1.ClientID%>');
if(comboboxId.value=="some value") {
alert("Error");
}
}
但我无法验证组合框。
我的html代码是:
<asp:ComboBox ID="ComboBox1" runat="server"
AutoCompleteMode="Suggest"
CaseSensitive="false"
DropDownStyle="DropDownList">
</asp:ComboBox>
浏览器上 ASP 生成的代码:
<div onchange="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$ContentPlaceHolder$ContentPlaceHolder1$unit\',\'\')', 0)"
id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit" style="display:inline;">
<table id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit_unit_Table"
class="ajax__combobox_inputcontainer" cellspacing="0" cellpadding="0" border="0"
style=
"border-width:0px;border-style:None;border-collapse:collapse;display:inline;position:relative;top:5px;">
<tr>
<td class="ajax__combobox_textboxcontainer">
<input type="text" autocomplete="off" style="width:150px;"
name="ctl00$ctl00$ContentPlaceHolder$ContentPlaceHolder1$unit$unit_TextBox"
id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit_unit_TextBox" />
</td>
<td class="ajax__combobox_buttoncontainer">
<button type="button"
id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit_unit_Button">
</button>
</td>
</tr>
</table>
<ul id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit_unit_OptionList"
class="ajax__combobox_itemlist" style="display:none;visibility:hidden;">
<li>GM</li>
<li>KG</li>
</ul>
<input type="hidden" value="0"
name="ctl00$ctl00$ContentPlaceHolder$ContentPlaceHolder1$unit$unit_HiddenField"\
id="ctl00_ctl00_ContentPlaceHolder_ContentPlaceHolder1_unit_unit_HiddenField"/>
</div>