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

  2. BillE

    Hans Kesting Guest

    I have an aspx page which contains 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. Advertisements

  3. Yes.
     
    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
     
    BillE, Aug 29, 2007
    #4
  5. Please show your code.
     
    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
     
    BillE, Aug 29, 2007
    #6
  7. BillE

    Joey Guest

    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. 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 [MVP], Aug 29, 2007
    #8
  9. BillE

    marss Guest

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

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 (here). After that, you can post your question and our members will help you out.