从我的日期选择器设置日期值 [英] Setting Date Value from my Date Picker
问题描述
我正在尝试在asp.net网页上获取日期选择器.我已经能够使用母版页运行相同的代码
并且可以正常工作,但是现在我正试图在没有主寻呼机的情况下使其正常工作,并且出现错误消息:
错误:无法获取属性"aspnetForm.ctl00_txtDOB"的值:对象为空或未定义
在我的Default.aspx页上....
I''m trying to get a date picker on my asp.net webpage. I''ve been able to run the same code using a master page
and it works, but now I''m trying to get it to work without a master pager and I''m getting error message:
Error: Unable to get value of the property ''aspnetForm.ctl00_txtDOB'': object is null or undefined
On my Default.aspx page....
<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');"/>
我已经尝试过onclick ="calendarPicker(''txtDOB'');"/>
我的date_picker.aspx.cs
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] .... window.opener.document.forms [0].{0}.值..........
Link.Attributes.Add("href",String.Format("JavaScript:window.opener.document.forms [0].{0} .value = \''{1:d} \''; window.close( );,Request.QueryString [" field],e.Day.Date));;
Got it!
Add forms[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));
这篇关于从我的日期选择器设置日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!