RegisterStartupScript doesn't work in a aspx page containing a frameset

B

BillE

I have an aspx page which contains a frameset.

I want to set the location.href of the frames dynamically using javascript
created in the Page_Load of the frameset using RegisterStartupScript, but
the registered script doesn't appear to run. Is there some reason why
RegisterStartupScript won't work in a aspx page containing a frameset?
 
H

Hans Kesting

I have an aspx page which contains a frameset.
I want to set the location.href of the frames dynamically using
javascript created in the Page_Load of the frameset using
RegisterStartupScript, but the registered script doesn't appear to
run. Is there some reason why RegisterStartupScript won't work in a
aspx page containing a frameset?

When you view the html source of that frameset page as it was
received by the browser, do you see the javascript there?

Just a wild guess: will javascript work in a frameset page? (I expect
it does, but you never know ...)

Hans Kesting
 
B

BillE

Thank you for the response.

I know that javascript works in a frameset page.

The problem is that when I attempt to insert javascript using
RegisterStartupScript in a frameset page the javascript is not created.

-Bill
 
M

Mark Rae [MVP]

The problem is that when I attempt to insert javascript using
RegisterStartupScript in a frameset page the javascript is not created.

Please show your code.
 
B

BillE

Thanks for looking at this for me. I expect I am overlooking something, but
I can't imagine what. It seems simple, but I can't think of anything else
to try.

I simplified it by creating a frameset with one frame containing a page.

The frameset uses RegisterStartupScript to insert javascript, but the
javascript doesn't get inserted.

The page which is the source of the frame uses identical code with
RegisterStartupScript to insert javascript which does work.

I also included some javascript hard coded in the frameset to verify that
javascript works in the frameset, and it does.

Thanks
Bill

----------------------------------
Here is the frameset page design - just a frameset with one frame. There is
a bit of javascript to verify that javascript works.
----------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Frameset1.aspx.vb"
Inherits="testing_Frameset1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language=javascript>
//this works
alert('Test Frameset 1');
</script>
</head>
<FRAMESET id=testFS cols=100% frameBorder=0 frameSpacing=0 >
<FRAME name=testFr1 id=testFr1 noResize src="Frameset1Frame1.aspx"
scrolling=no>
</FRAMESET>
</html>



----------------------------------
Here is the Code Behind of the frameset page:
----------------------------------

Partial Class testing_Frameset1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'This javascript doesn't get inserted
Dim sScript As String = "alert('test Frameset Startup Script');"
Dim csm As ClientScriptManager = Page.ClientScript
sScript = "<script language=javascript>" + sScript + "</script>"
csm.RegisterStartupScript(Me.GetType, "testFS", sScript)
End Sub
End Class



----------------------------------
Here is the Code Behind of the source page for a frame:
----------------------------------

Partial Class testing_Frameset1Frame1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'This javascript gets inserted and works
Dim sScript As String = "alert('test Frame');"
Dim csm As ClientScriptManager = Page.ClientScript 'Me.ClientScript
'
sScript = "<script language=javascript>" + sScript + "</script>"
csm.RegisterStartupScript(Me.GetType, "testFrame", sScript)

End Sub
End Class
 
J

Joey

Thanks for looking at this for me. I expect I am overlooking something, but
I can't imagine what. It seems simple, but I can't think of anything else
to try.

I simplified it by creating a frameset with one frame containing a page.

The frameset uses RegisterStartupScript to insert javascript, but the
javascript doesn't get inserted.

The page which is the source of the frame uses identical code with
RegisterStartupScript to insert javascript which does work.

I also included some javascript hard coded in the frameset to verify that
javascript works in the frameset, and it does.

Thanks
Bill

----------------------------------
Here is the frameset page design - just a frameset with one frame. There is
a bit of javascript to verify that javascript works.
----------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Frameset1.aspx.vb"
Inherits="testing_Frameset1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language=javascript>
//this works
alert('Test Frameset 1');
</script>
</head>
<FRAMESET id=testFS cols=100% frameBorder=0 frameSpacing=0 >
<FRAME name=testFr1 id=testFr1 noResize src="Frameset1Frame1.aspx"
scrolling=no>
</FRAMESET>
</html>

----------------------------------
Here is the Code Behind of the frameset page:
----------------------------------

Partial Class testing_Frameset1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'This javascript doesn't get inserted
Dim sScript As String = "alert('test Frameset Startup Script');"
Dim csm As ClientScriptManager = Page.ClientScript
sScript = "<script language=javascript>" + sScript + "</script>"
csm.RegisterStartupScript(Me.GetType, "testFS", sScript)
End Sub
End Class

----------------------------------
Here is the Code Behind of the source page for a frame:
----------------------------------

Partial Class testing_Frameset1Frame1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'This javascript gets inserted and works
Dim sScript As String = "alert('test Frame');"
Dim csm As ClientScriptManager = Page.ClientScript 'Me.ClientScript
'
sScript = "<script language=javascript>" + sScript + "</script>"
csm.RegisterStartupScript(Me.GetType, "testFrame", sScript)

End Sub
End Class





- Show quoted text -

I would also set the XHTML doctype to frameset, instead of
transitional. I believe you are supposed to do that when using frames.

JP
 
M

marss

The frameset uses RegisterStartupScript to insert javascript, but the
javascript doesn't get inserted.

The page which is the source of the frame uses identical code with
RegisterStartupScript to insert javascript which does work.

Script that was registered by RegisterStartupScript method is rendered
while form renders. No form - no script.
Try this (code in C#, I guess you will understand):

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<%= GetScript() %>
</head>
<FRAMESET id=testFS cols=100% frameBorder=0 frameSpacing=0 >
<FRAME name=testFr1 id=testFr1 noResize src="Frameset1Frame1.aspx"
scrolling=no>
</FRAMESET>
</html>

Add protected function that returns string value in the codebehind
file:

protected string GetScript()
{
string script = "<script type='text/javascript'> alert('Test
Frameset 1'); </script>";
return script;
}

Regards,
Mykola
http://marss.co.ua
 
B

BillE

I'll do that.

Apparently, however, RegisterStartupScript won't work in frameset pages
because there is no <form> tag, according to the post from "marss".

Thanks!
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top