Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > RegisterStartupScript doesn't work in a aspx page containing a frameset

Reply
Thread Tools

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

 
 
BillE
Guest
Posts: n/a
 
      08-28-2007
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?


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      08-29-2007
> 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


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-29-2007
"Hans Kesting" <> wrote in message
news: om...

> Just a wild guess: will javascript work in a frameset page?


Yes.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
BillE
Guest
Posts: n/a
 
      08-29-2007
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
"Hans Kesting" <> wrote in message
news: om...
>> 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
>
>



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-29-2007
"BillE" <> wrote in message
news:...

> 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.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
BillE
Guest
Posts: n/a
 
      08-29-2007
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


"Mark Rae [MVP]" <> wrote in message
news:...
> "BillE" <> wrote in message
> news:...
>
>> 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.
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Joey
Guest
Posts: n/a
 
      08-29-2007
On Aug 29, 8:11 am, "BillE" <bel...@datamti.com> wrote:
> 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
>
> "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote in messagenews:. ..
>
>
>
> > "BillE" <bel...@datamti.com> wrote in message
> >news:...

>
> >> 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.

>
> > --
> > Mark Rae
> > ASP.NET MVP
> >http://www.markrae.net- Hide quoted text -

>
> - 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

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-29-2007
"Joey" <> wrote in message
news: ups.com...

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


Yes, that's correct.

Also, script language=javascript is deprecated syntax and not
XHTML-compliant - is this instead:

<script type="text/javascript">

or, even better, get ASP.NET to inject the script tags automatically:
http://msdn2.microsoft.com/en-us/lib...8y(VS.80).aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      08-29-2007
On 29 , 16:11, "BillE" <bel...@datamti.com> wrote:

> 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

 
Reply With Quote
 
BillE
Guest
Posts: n/a
 
      08-29-2007
Thanks Marss. I didn't know that.
I'll try your technique...

-Bill

"marss" <> wrote in message
news: oups.com...
> On 29 , 16:11, "BillE" <bel...@datamti.com> wrote:
>
>> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to a frameset causes the frameset to resize xzzy ASP .Net 4 03-23-2006 10:31 PM
How to leave a frameset for opening a new frameset with a JavaScript Stefan Mueller Javascript 0 11-07-2005 09:44 AM
Frameset, Selected Index, Target Frameset relchatt@comcast.net ASP .Net 0 09-29-2004 09:37 PM
Changing src of a frame of a frameset within another frameset? Julius Mong Javascript 1 05-10-2004 07:35 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57