master pages using JS from external file?

Discussion in 'ASP .Net' started by Flip, Nov 22, 2005.

  1. Flip

    Flip Guest

    I have a website that's using Master pages (very cool). But when I put JS
    on there (to close the browser for example) coming from an external file,
    when I navigate away from the first page, the JS no longer works. Can
    someone explain why this is happening? How can I fix this so that the JS is
    generic enough to work on every aspx to be included in the external JS file?

    The external JS file looks like this right now

    function closePage()
    {
    this.window.close();
    }

    I've tried it without the this, but then nothing seemed to work.

    Thank you.
     
    Flip, Nov 22, 2005
    #1
    1. Advertising

  2. Flip

    Karl Seguin Guest

    Is the problem just pathing?

    like, you have src="scripts/close.js"

    and it works when ur in
    /index.aspx
    but not when ur in
    /user/blah.aspx ?

    if so, just stick something like

    src="<%=REquest.ApplicationPath%>/scripts/close.js"

    karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Flip" <[remove]> wrote in message
    news:...
    >I have a website that's using Master pages (very cool). But when I put JS
    >on there (to close the browser for example) coming from an external file,
    >when I navigate away from the first page, the JS no longer works. Can
    >someone explain why this is happening? How can I fix this so that the JS
    >is generic enough to work on every aspx to be included in the external JS
    >file?
    >
    > The external JS file looks like this right now
    >
    > function closePage()
    > {
    > this.window.close();
    > }
    >
    > I've tried it without the this, but then nothing seemed to work.
    >
    > Thank you.
    >
     
    Karl Seguin, Nov 22, 2005
    #2
    1. Advertising

  3. Flip

    Flip Guest

    > Is the problem just pathing?
    hhhmm that might be it? So simple, and I missed it! :< I just assumed that
    I wasn't getting any errors, and that it worked from the root, all was ok.
    But now that you mention it, I think you're right, the problem is with the
    sub paths only! DOH!

    Thank you very much! :>
     
    Flip, Nov 22, 2005
    #3
  4. Flip

    Flip Guest

    > src="<%=REquest.ApplicationPath%>/scripts/close.js"
    YAHOO! That worked! Beautiful and thank you! :>
     
    Flip, Nov 23, 2005
    #4
  5. Flip

    clintonG Guest

    Doesn't work for me when used in the Master...
    The Controls collection cannot be modified because the control contains code
    blocks (i.e. <% ... %>).

    <%= Clinton Gallagher

    "Flip" <!REMOVE_ME!> wrote in message
    news:...
    >> src="<%=REquest.ApplicationPath%>/scripts/close.js"

    > YAHOO! That worked! Beautiful and thank you! :>
    >
     
    clintonG, Nov 23, 2005
    #5
  6. Flip

    Flip Guest

    Did you surround the outside with?





    "clintonG" <> wrote in message
    news:...
    > Doesn't work for me when used in the Master...
    > The Controls collection cannot be modified because the control contains
    > code blocks (i.e. <% ... %>).
    >
    > <%= Clinton Gallagher
    >
    > "Flip" <!REMOVE_ME!> wrote in message
    > news:...
    >>> src="<%=REquest.ApplicationPath%>/scripts/close.js"

    >> YAHOO! That worked! Beautiful and thank you! :>
    >>

    >
    >
     
    Flip, Nov 23, 2005
    #6
  7. Flip

    Flip Guest

    SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
    with quotes?

    Something like this.


    <script
    language="Javascript"
    type="text/javascript"
    src="<%=Request.ApplicationPath()%>/ButtonHandlers.js">
    </script>

    I'm going from memory, but I HTH. Good luck.
     
    Flip, Nov 23, 2005
    #7
  8. Flip

    clintonG Guest

    Here's what I used...

    <head runat="server">
    <script src="<%= Request.ApplicationPath %>/Scripts/scripts.js"
    type="text/JavaScript"></script>
    </head>

    That raises this error...
    The Controls collection cannot be modified because the control contains code
    blocks (i.e. <% ... %>).

    Catch-22...
    This HTML web server control -- <head runat="server"> -- is raising the
    exception and we can not remove runat="server" from the head element when
    using 2.0 Themes. Thus, we can not use ServerVariables with expressions to
    dynamically assign a path or we have to remove runat="server" and stop using
    Themes. Nice choice.

    A Page_Load Solution...

    #region Write External JavaScript Library <script> Declaration...

    // Dynamically assign path to external Javascript library src
    attribute
    // by writing <script...></script> into the body of the page
    // obviating the need for <script...></script> to be located in
    the
    // <head> element which imposes conflict when using Themes.

    // Define an arbitrary but unique name to use as a key
    String key = "ExternalJavaScriptReference";
    String url = Request.ApplicationPath + "/Scripts/scripts.js";

    // Instantiate ClientScriptManager object
    ClientScriptManager cs = Page.ClientScript;

    // Do not register if this instance of the key is already
    registered.
    if (!cs.IsClientScriptIncludeRegistered(key))
    {
    cs.RegisterClientScriptInclude(key, url);
    }
    #endregion

    <%= Clinton Gallagher
    METROmilwaukee (sm) "A Regional Information Service"
    NET csgallagher AT metromilwaukee.com
    URL http://metromilwaukee.com/
    URL http://clintongallagher.metromilwaukee.com/




    "Flip" <[remove]> wrote in message
    news:...
    > SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
    > with quotes?
    >
    > Something like this.
    >
    >
    > <script
    > language="Javascript"
    > type="text/javascript"
    > src="<%=Request.ApplicationPath()%>/ButtonHandlers.js">
    > </script>
    >
    > I'm going from memory, but I HTH. Good luck.
    >
     
    clintonG, Nov 24, 2005
    #8
  9. Flip

    Karl Seguin Guest

    you cn simply give you <Script tag a runat="server" and declare the path in
    the codebehind of your master page.

    protected HtmlGenericControl script;

    load
    script.Attributes["src"] = Request.ApplicationPath +
    script.Attributes["src"]

    or something

    karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "clintonG" <> wrote in message
    news:%...
    > Here's what I used...
    >
    > <head runat="server">
    > <script src="<%= Request.ApplicationPath %>/Scripts/scripts.js"
    > type="text/JavaScript"></script>
    > </head>
    >
    > That raises this error...
    > The Controls collection cannot be modified because the control contains
    > code blocks (i.e. <% ... %>).
    >
    > Catch-22...
    > This HTML web server control -- <head runat="server"> -- is raising the
    > exception and we can not remove runat="server" from the head element when
    > using 2.0 Themes. Thus, we can not use ServerVariables with expressions to
    > dynamically assign a path or we have to remove runat="server" and stop
    > using Themes. Nice choice.
    >
    > A Page_Load Solution...
    >
    > #region Write External JavaScript Library <script> Declaration...
    >
    > // Dynamically assign path to external Javascript library src
    > attribute
    > // by writing <script...></script> into the body of the page
    > // obviating the need for <script...></script> to be located in
    > the
    > // <head> element which imposes conflict when using Themes.
    >
    > // Define an arbitrary but unique name to use as a key
    > String key = "ExternalJavaScriptReference";
    > String url = Request.ApplicationPath + "/Scripts/scripts.js";
    >
    > // Instantiate ClientScriptManager object
    > ClientScriptManager cs = Page.ClientScript;
    >
    > // Do not register if this instance of the key is already
    > registered.
    > if (!cs.IsClientScriptIncludeRegistered(key))
    > {
    > cs.RegisterClientScriptInclude(key, url);
    > }
    > #endregion
    >
    > <%= Clinton Gallagher
    > METROmilwaukee (sm) "A Regional Information Service"
    > NET csgallagher AT metromilwaukee.com
    > URL http://metromilwaukee.com/
    > URL http://clintongallagher.metromilwaukee.com/
    >
    >
    >
    >
    > "Flip" <[remove]> wrote in message
    > news:...
    >> SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
    >> with quotes?
    >>
    >> Something like this.
    >>
    >>
    >> <script
    >> language="Javascript"
    >> type="text/javascript"
    >> src="<%=Request.ApplicationPath()%>/ButtonHandlers.js">
    >> </script>
    >>
    >> I'm going from memory, but I HTH. Good luck.
    >>

    >
    >
     
    Karl Seguin, Nov 24, 2005
    #9
  10. Flip

    vkona

    Joined:
    Jul 31, 2007
    Messages:
    1
    master pages using JS from external file

    the javascript function from external file is firing when i kept this

    <script type='text/javascript' src="<%=Request.ApplicationPath%>/presentationLayer/JSFiles/CalendarControl.js" language='javascript' />


    path in master page, but all the post back events (like button_click) are not working.

    When that is removed all the events are working fine.
    is there any problem?

    is there any solution to make work both.

    :!:
     
    Last edited: Jul 31, 2007
    vkona, Jul 31, 2007
    #10
    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. Doug McCann
    Replies:
    1
    Views:
    1,100
    William Brogden
    Aug 5, 2004
  2. Glenn
    Replies:
    0
    Views:
    456
    Glenn
    May 10, 2006
  3. Replies:
    1
    Views:
    3,262
    PeterKellner
    May 16, 2006
  4. =?Utf-8?B?RG9u?=

    Using Master Pages and Base Pages

    =?Utf-8?B?RG9u?=, Sep 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    S. Justin Gengo
    Sep 12, 2006
  5. katmagic
    Replies:
    0
    Views:
    1,290
    katmagic
    Dec 26, 2008
Loading...

Share This Page