Click here to Skip to main content
15,937,602 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to get a date picker on my 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) {'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

           // 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

Updated 8-Sep-12 3:38am

1 solution

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));
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900