當我嘗試點擊我的日曆控件時,出現javascript錯誤。Javascript錯誤:'window.top.document.getElementById(...)'爲空或不是對象
的HTML代碼是:
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
我的錯誤:
<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>
當我點擊日曆控件的日期,這個代碼在代碼隱藏運行得到的是'window.top.document.getElementById(...)'爲空或不是對象
I確實有一個名爲FromDate的對象。
還有什麼可能導致此錯誤?
是從iframe中運行的代碼,或託管的網頁? –
代碼隱藏在iframe中。該HTML是在託管頁面 – Csharp
你能解決這個問題? – Troy