我正在尝试通过 javascript 函数在 ascx 页面中调用服务器端方法。此方法在 aspx 页面中有效。它似乎没有调用 javascript 函数,但隐藏按钮确实调用了服务器端方法。
<div runat="server">
<script type="text/javascript">
function WebDatePicker_DayChange(sender, eventArgs)
{
document.getElementById("HiddenField3").value = eventArgs.get_value();
var btn = document.getElementById("Button2");
btn.click();
}
</script></div>
<ig:WebDatePicker runat="server" ID="WebDatePicker1" DropDownCalendarID="webMonthCalendar" DisplayModeFormat="MM/dd/yyyy" EditModeFormat="MM/dd/yyyy" EditMode="CalendarOnly" Nullable="False" AlwaysInEditMode="False" HorizontalAlign ="Center" >
<ClientSideEvents ValueChanged="WebDatePicker_DayChange" ></ClientSideEvents>
</ig:WebDatePicker>
<ig:WebMonthCalendar runat="server" ID="webMonthCalendar" Culture="en-us" FooterContent="Today: {0:d}"
EnableWeekNumbers="false"
ChangeMonthToDateClicked="true"
EnableMonthDropDown="True"
EnableYearDropDown="True">
</ig:WebMonthCalendar>
<input type="button" id="Button2" style="display:none" runat="server" onserverclick="WebDatePicker_DayChange" />
<asp:HiddenField ID="HiddenField3" runat="server" Value="" />