Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am using frames for my web application. 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.


Problem: Button click works perfectly in Internet Explorer 8.0 on production machine, Windows XP, 32 bit.

Button click event doesn't open anything in the right frame, just remains as it is, in 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.

share|improve this question
    
What error message (if any) do you see in the browser's console window? I don't think using parentheses to index into an array is valid JavaScript... – Chris Shouts Aug 23 '11 at 17:37
up vote 1 down vote accepted

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 (); 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. Once I changed to the correct syntax, the code worked fine in all browsers.

share|improve this answer

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.

share|improve this answer
    
The last parameter passed to RegisterStartupScript is bool addScriptTags. In this case, the parameter is false, so the <script> tags are necessary. – Chris Shouts Aug 23 '11 at 17:39
    
good catch, I've always set mine to true. – Itskiddly Aug 23 '11 at 17:42
    
Hi all, I have tried these suggestions (verified it several times) but still the problem persists. I really appreciate the responses.Any other suggestions are welcome. – Sree Aug 25 '11 at 17:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.