简体   繁体   English

ASP.NET(将VB.NET用于后面的代码)框架问题

[英]ASP.NET (using VB.NET for code behind) Frames issue

I am using frames for my web application. 我正在为Web应用程序使用框架。 Description (1)Left Frame with a list of buttons (clicking them opens a web page in the right frame) (2)Right Frame, opens the web page passed by the left frame. 说明(1)带有按钮列表的左框架(单击它们会在右框架中打开一个网页)(2)右框架,将打开由左框架传递的网页。


Problem: Button click works perfectly in Internet Explorer 8.0 on production machine, Windows XP, 32 bit. 问题:在32位Windows XP生产计算机上的Internet Explorer 8.0中,单击按钮的效果很好。

Button click event doesn't open anything in the right frame, just remains as it is, in Firefox, Chrome, Internet Explorer 9.0 在Firefox,Chrome,Internet Explorer 9.0中,按钮单击事件不会在右框架中打开任何内容,只是保持原样


Intial code that loads the frames 加载框架的初始代码

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="frmMain.aspx.vb" Inherits="XYZ" smartNavigation="True"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"  http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <TITLE>frmMain</</TITLE>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<frameset COLS="20%,80%">
    <frame name="frame1" src="frmbuttons.aspx">
    <frame name="frame2" src="frmbegin.aspx">
</frameset>

Example code (for a button in left frame): 示例代码(用于左侧框架中的按钮):

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim url As String = String.Empty
url = "test.aspx"
Dim frameScript As String = "<script language='javascript'>" & "window.parent.frames(1).location='" & url & "';</script>"

ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "FrameScript", frameScript, False)
end sub

Any help will be appreciated. 任何帮助将不胜感激。

I found the solution. 我找到了解决方案。 This code causes an error: 此代码导致错误:

Dim frameScript As String = "window.parent.frames(1).location='" & url & "'"

The above line has an error in window.parent.frames(1) because of the parenthesis () ; 上一行由于括号()导致window.parent.frames(1)出现错误。 the correct solution to this problem would be: 解决此问题的正确方法是:

This code is correct: 这段代码是正确的:

Dim frameScript As String = "window.parent.frames[1].location='" & url & "'"

VB.Net uses parenthesis for array index access, but Javascript uses square brackets. VB.Net使用括号来进行数组索引访问,但是Javascript使用方括号。 Once I changed to the correct syntax, the code worked fine in all browsers. 一旦更改为正确的语法,该代码就可以在所有浏览器中正常工作。

Have you tried: 你有没有尝试过:

Dim frameScript As String = "window.parent.frames(1).location='" & url & "'"
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "FrameScript", frameScript, False)

In my experience with ScriptManager, I've never needed the tags, and it's always worked in IE, chrome and FF. 根据我在ScriptManager方面的经验,我从不需要标签,并且始终在IE,chrome和FF中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM