当我尝试点击我的日历控件时出现javascript错误。
html代码为:
<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>
当我点击日历控件中的日期时,此代码将在代码隐藏中执行:
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
我得到的错误是'window.top.document.getElementById(...)'为null或不是对象
我有一个名为FromDate的对象 还有什么可能导致这个错误?
答案 0 :(得分:6)
尝试使用window.parent.document.getElementById()
代替window.top.document.getElementById()
答案 1 :(得分:2)
你试过parent.document.getElementById(...)
吗?只是一个想法...
按照pimvdb
的建议编辑