我正在尝试在我的 asp.net 网页上获取日期选择器。我已经能够使用母版页运行相同的代码并且它可以工作,但现在我试图让它在没有母版页的情况下工作,我收到错误消息:错误:无法获取属性的值'aspnetForm.ctl00_txtDOB': 对象为空或未定义
在我的 Default.aspx 页面上......
<script language="javascript" type="text/javascript">
function calendarPicker(strField) {
window.open('date_picker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}
<label>DOB:</label><asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
<img src="images/calendar.gif" alt="Pick To Date" onclick="calendarPicker('aspnetForm.ctl00_txtDOB');"/>
I already tried onclick="calendarPicker('txtDOB');"/>
My date_picker.aspx.cs
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
// Clear the link from this day
e.Cell.Controls.Clear();
// Add the custom link
System.Web.UI.HtmlControls.HtmlGenericControl Link = new System.Web.UI.HtmlControls.HtmlGenericControl();
Link.TagName = "a";
Link.InnerText = e.Day.DayNumberText;
Link.Attributes.Add("href", String.Format("JavaScript:window.opener.document.{0}.value = \'{1:d}\'; window.close();", Request.QueryString["field"], e.Day.Date));
// By default, this will highlight today's date.
if (e.Day.IsSelected)
{
Link.Attributes.Add("style", this.Calendar1.SelectedDayStyle.ToString());
}
// Now add our custom link to the page
e.Cell.Controls.Add(Link);
}