Javascript is loaded only in IE9 Compatibility Mode

Posted on 2012-09-19
Last Modified: 2012-09-20
I have a really strange issue.
My Application loads some user-controls (.ascx) dynamicly.
For some of them i need a javascript function that is stored in

so i tried to register this script in Init and Load events of my UserControl.
        Dim sPath As String = Page.ResolveClientUrl("~/Scripting/LiteUCScripts/LiteUCSripts.js")
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "LucJS", sPath)

Open in new window

like also on the Usercontrol-Page with:
<script src="<%= ResolveClientUrl("~/Scripting/LiteUCScripts/LiteUCScripts.js") %>"  type="text/javascript"></script>

Open in new window

The Issue:
Javascript-File would be only registered if the Browser is in IE9 Compatibility Mode!
Turning the IE in default Mode IE9 the Javascript results in not registered Javascript file.

I will not register it on Masterpage or elsewhere, because i will that my usercontrol can be simply used in other projects, and so that developpers dont have to invest immensely effort to implement this control in their projects.

Does somebody has a idea why this is not working in IE9 default Mode.
Question by:markus_pluess
    LVL 38

    Accepted Solution

    A couple of longshots.
    1.) GetType is a method so it needs the parenthesis as in Me.GetType()
    2.) I have found that using the tilde to get to the root is unreliable. So instead of ~/ you could try:    Scripting/LiteUCScripts/LiteUCScripts.js    (start in the current directory)
    or:    ./Scripting/LiteUCScripts/LiteUCScripts.js   (start in the current directory)
    or:    ../Scripting/LiteUCScripts/LiteUCScripts.js  (start in the parent directory)

    This forum post says:
    The solution to this issue is to use the following code:

    Control Caller = this; //the user control that you are calling from
    ScriptManager.RegisterStartupScript(Caller, typeof(Caller), "Script Name", Script.ToString(), true);
    The Script manager has trouble adding scripts to the Page object from a user control and must have a reference to the calling user control.

    But the question was not specific to IE9. Still it could be significant.

    Author Closing Comment

    Thanks a lot, i tried your solution with "ScriptManager.RegisterStartupScript" and that worked for me!
    Thousand thanks!
    LVL 38

    Expert Comment

    by:Tom Beck
    Great. Thanks for the points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    A short article about a problem I had getting the GPS LocationListener working.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now