我正在尝试在我的asp.net网页上获取日期选择器。我已经能够使用母版页运行相同的代码 它的工作原理,但现在我试图让它在没有母版寻呼机的情况下工作,我收到错误消息: 错误:无法获取属性'aspnetForm.ctl00_txtDOB'的值:object为null或undefined
在我的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);
}
答案 0 :(得分:1)
尝试更改此内容:
onclick="calendarPicker('aspnetForm.ctl00_txtDOB');"
对此:
onclick="calendarPicker('<%=txtDOB.ClientID %>');"
答案 1 :(得分:0)
我这样做是为了工作:
添加表格[0] .... window.opener.document.forms [0]。{0} .value ..........
Link.Attributes.Add(“href”,String.Format(“JavaScript:window.opener.document.forms [0]。{0} .value = \'{1:d} \'; window.close ();“,Request.QueryString [”field“],e.Day.Date));