在我的網站我有兩個頁面內一個asp.net頁面...一個是Assistance.aspx
,另一個是Help01.aspx
我想要做的就是打開裏面的iFrame
第二頁這是在此列屬於表這是Assistance.aspx
頁的內表列:
爲此我使用下面的代碼:
打開一個iframe
<iframe id="iFrame" runat="server" class="tablecolumndiv" >
在我後面的代碼我使用:
Protected WithEvents iFrame As System.Web.UI.HtmlControls.HtmlGenericControl<br/>
Public frame1 As HtmlControl = CType(Me.FindControl("iFrame"), HtmlControl)
但是,當我來到了:
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
frame1.Attributes("src") = "/Pages/Support/Asp/Help01.aspx"
End Sub
這引發了我的錯誤:
Object reference not set to an instance of an object.
因爲Me.FindControl("iFrame")
有什麼
值 當我刪除消除了錯誤runat
來自元素。 爲什麼?
*其它信息*
我也用下面的腳本出於同樣的原因:
<script type="text/javascript">
function setPage(frame, pName) {
document.getElementById(frame).src = pName;
}
</script>
我稱之爲從我後面的代碼:
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
Dim myNewAsp As New AspNetSqlProvider
myNewAsp.InitializeSite(sender, e)
Dim url As String = "/Pages/Support/Asp/Help01.aspx"
Dim urlURI As String = HttpContext.Current.Request.Url.AbsoluteUri
Dim urlPath As String = HttpContext.Current.Request.Url.AbsolutePath
Dim myServerName As String = Strings.Left(urlURI, urlURI.Length - urlPath.Length)
root_url = myServerName
Dim assist As New Assistance
Dim frameName As String = "iFrame" 'assistiFrame.ID
iPageLoad(frameName, sender, root_url + url)
End Sub
Public Sub iPageLoad(FrameId As String, sender As Object, msg As String)
Dim cstype As Type = Me.GetType()
Dim innerMess As String = msg
Dim url As String = HttpContext.Current.Request.Url.AbsoluteUri
Dim script As String = "setPage('" + FrameId + "', '" + innerMess + "')"
If Not Page.ClientScript.IsStartupScriptRegistered(Me.GetType(), "iPage") Then
Page.ClientScript.RegisterStartupScript(cstype, "iPage", script, True)
End If
End Sub
該腳本也引發了同樣的錯誤。
當您刪除runat = server標籤時,我認爲代碼本身不起作用?你也關閉iframe標籤嗎? –
無代碼運行順利,我不關閉'iFrame' –
你有沒有試過'iFrame.Attributes(「SRC」)=「/Pages/Support/Asp/Help01.aspx」'?直接,沒有使用FindControl – Satpal