如果看不到生成的HTML,很难知道,但我的第一个猜测是,您的控件没有将类名直接应用于
<input>
田野…或者你依赖
id
以某种方式(嵌入到用户控件中时可能会发生变化)。
在您发布的HTML中,这些内容显示为三个相关部分:
块1(控件:日期选取器)
<div id="datePicker_Div0" class="AdminRowOdd DERow">
<div id="datePicker_Div1" class="DELabel">
<span id="datePicker_DateLabel">Date</span>
</div>
<div id="datePicker_Div2" class="DEInput datePicker">
<input name="datePicker$DateSelector" type="text"
onchange="javascript:setTimeout('__doPostBack(\'datePicker$DateSelector\',\'\')', 0)"
onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;"
id="datePicker_DateSelector" style="width:80px;" />
<select name="datePicker$languageSelector"
onchange="javascript:setTimeout('__doPostBack(\'datePicker$languageSelector\',\'\')', 0)"
id="datePicker_languageSelector">
<option selected="selected" value="en-US">en-US</option>
<option value="fr-CA">fr-CA</option>
<option value="fr-FR">fr-FR</option>
<option value="es-ES">es-ES</option>
<option value="es-MX">es-MX</option>
</select>
</div>
</div>
…
块2(控件:日期1)
<div id="date1_Div0" class="AdminRowOdd DERow">
<div id="date1_Div1" class="DELabel">
<span id="date1_DateLabel">Date</span>
</div>
<div id="date1_Div2" class="DEInput datePicker">
<input name="date1$DateSelector" type="text"
onchange="javascript:setTimeout('__doPostBack(\'date1$DateSelector\',\'\')', 0)"
onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;"
id="date1_DateSelector" style="width:80px;" />
<select name="date1$languageSelector"
onchange="javascript:setTimeout('__doPostBack(\'date1$languageSelector\',\'\')', 0)"
id="date1_languageSelector">
<option selected="selected" value="en-US">en-US</option>
<option value="fr-CA">fr-CA</option>
<option value="fr-FR">fr-FR</option>
<option value="es-ES">es-ES</option>
<option value="es-MX">es-MX</option>
</select>
</div>
</div>
…
块3(jquery datepicker wireup)
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function()
{
// matches input element for first control only (id selector)
var cal = jQuery('#datePicker_DateSelector')
.datepicker({yearRange: '-1500:+100',dateFormat: 'm/d/yy'});
});
Sys.Application.initialize();
//]]>
</script>
问题出在最后一块。选择器特定于第一个控件,按ID匹配。如果它被修改为包含对第二个控件的单独调用…
var cal = jQuery('#datePicker_DateSelector')
.datepicker({yearRange: '-1500:+100',dateFormat: 'm/d/yy'});
var cal2 = jQuery('#date1_DateSelector')
.datepicker({yearRange: '-1500:+100',dateFormat: 'm/d/yy'});
…或更通用的选择器…
// matches all text input elements that are descendants of
// a div element with a class of datePicker
var cal = jQuery('div.datePicker input:text')
.datepicker({yearRange: '-1500:+100',dateFormat: 'm/d/yy'});
…那么事情应该按预期进行。