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

Discussion in 'ASP .Net' started by BillE, Aug 29, 2007.

  1. BillE

    BillE Guest

    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?
    BillE, Aug 29, 2007
    #1
    1. Advertising

  2. BillE

    Hans Kesting Guest

    > 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
    Hans Kesting, Aug 29, 2007
    #2
    1. Advertising

  3. "Hans Kesting" <> wrote in message
    news:...

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


    Yes.


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 29, 2007
    #3
  4. BillE

    BillE Guest

    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:...
    >> 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
    >
    >
    BillE, Aug 29, 2007
    #4
  5. "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
    Mark Rae [MVP], Aug 29, 2007
    #5
  6. BillE

    BillE Guest

    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
    BillE, Aug 29, 2007
    #6
  7. BillE

    Joey Guest

    On Aug 29, 8:11 am, "BillE" <> 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]" <> wrote in messagenews:...
    >
    >
    >
    > > "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- 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
    Joey, Aug 29, 2007
    #7
  8. "Joey" <> wrote in message
    news:...

    > 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/library/z9h4dk8y(VS.80).aspx


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 29, 2007
    #8
  9. BillE

    marss Guest

    On 29 , 16:11, "BillE" <> 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
    marss, Aug 29, 2007
    #9
  10. BillE

    BillE Guest

    Thanks Marss. I didn't know that.
    I'll try your technique...

    -Bill

    "marss" <> wrote in message
    news:...
    > On 29 , 16:11, "BillE" <> 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
    >
    BillE, Aug 29, 2007
    #10
  11. BillE

    BillE Guest

    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

    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "Joey" <> wrote in message
    > news:...
    >
    >> 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/library/z9h4dk8y(VS.80).aspx
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    BillE, Aug 29, 2007
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    657
  2. xzzy
    Replies:
    4
    Views:
    629
  3. AmitKu
    Replies:
    3
    Views:
    894
  4. ck388
    Replies:
    1
    Views:
    548
    ck388
    Sep 24, 2003
  5. Julius Mong
    Replies:
    1
    Views:
    360
    Randy Webb
    May 10, 2004
Loading...

Share This Page