I am getting a javascript error when I attempt to click on my calendar control.
The html code is:
<td align="left" style="width:50%;"><asp:Label runat="server" CssClass="TextFontBold" ID="lblStartDate" Text="Start Date:"></asp:Label>
<input type="text" class="TextBox" id="FromDate" runat="server"/><a href="javascript:ShowCalendar('FromDate1')"><img src="images/Calendar.png" border="0" /></a>
<iframe src="Calendar.aspx?DateTextID=FromDate" style="display:none; top: 0px; left: 0px; width:245px; height:164px" frameborder="0" scrolling="no" name="FromDate1" id="FromDate1"></iframe>
<asp:Label runat="server" CssClass="TextFontBold" ID="lblPromoStartTime" Text="Start Time:"></asp:Label>
</td>
When I click on a date in the calendar control, this code is executed on the code-behind:
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim strjscript As String = "<script language=""javascript"" type=""text/javascript"">"
strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "').value = '" & Calendar1.SelectedDate & "';"
strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "1').style.display = 'none';"
strjscript = strjscript & "</script" & ">"
Literal1.Text = strjscript
End Sub
The error I am getting is 'window.top.document.getElementById(...)' is null or not an object
I do have an object called FromDate.
What else could be causing this error?
Try window.parent.document.getElementById() instead of window.top.document.getElementById()
Have you tried parent.document.getElementById(...)? Just an idea...
Edited as suggested by pimvdb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With