• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

Javascript is loaded only in IE9 Compatibility Mode

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.
  • 2
1 Solution
Tom BeckCommented:
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.
markus_pluessAuthor Commented:
Thanks a lot, i tried your solution with "ScriptManager.RegisterStartupScript" and that worked for me!
Thousand thanks!
Tom BeckCommented:
Great. Thanks for the points.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now