FORUMS

c360 Forums
 Home        Members    Calendar    Who's On

Welcome Guest ( Login | Register )
      



Order of js-files when using...Expand / Collapse
Message
Posted 9/3/2007 5:45:40 AMPost #1740
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Hi,

We encountered a problem when trying to include javascript files in our pages with the Instance.RegisterClientScriptFile method.

We have a common javascript file and a page specific one. Sometimes the page-specific file holds code that calls functions from the common one. In our codebehind for the page, we would typically have code like this in the constructor for the page:

// Register stylesheets and javascript files or blocks
Instance.RegisterClientScriptFile("../JavaScript/NCCommon.js");
Instance.RegisterClientScriptFile("../JavaScript/PhoneResult.js");

However, on some pages - not all - the order in which the files are included has not been preserved. Hence, code in PhoneResult.js fails, as the methods called that are in the NCCommon.js file are not found, as that file is first included later in the output html.

Does anyone have an idea to why this happens and what can be done to ensure the files are loaded in the proper order?

best regards
Henrik Nielsen

--
Henrik Nielsen
Posted 9/4/2007 8:39:33 AMPost #1743
 

c360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guru
However, on some pages - not all - the order in which the files are included has not been preserved.

This is very odd!

Can you post your code so I can attempt to reproduce?

 

Posted 9/11/2007 4:14:30 AMPost #1762
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Hi,

Thanks for your reply, I have sent you a private message with an example of code-gone-wrong attached

We have have 4 pages where this happens. On the other hand we have roughly 7-8 pages where there is no issue, all pages are based on the SavePage and are based off the basic structure.

kind regards,
Henrik Nielsen

--
Henrik Nielsen
Posted 9/11/2007 6:25:56 PMPost #1763
 

c360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guruc360 Product Guru
Thanks for your code. I was able to reproduce the issue and in fact I was able to prove that the problem is not specific to your code. The issue is that our SDK maintains the names of the JavaScript files that have been "registered" in a HashTable and, evidently, C# sorts the items in a hashtable which results in the JavaScript files to be included in an unpredictable way. I am not sure what sorting algorithm C# uses, but it doesn't appear to be alphabetical.

Since the sorting is based on the file's name, it explains why some of your pages are fine while others have their .JS files in the wrong order.

Anyway, to make a long story short, I think I have a workaround. I conducted a few tests and it appears to work fine but I don't guarantee it: when you register a JavaScript file, you should specify a "key" instead of accepting the default behavior which is to use the file name as the key. You just need to make sure the the keys you specify are in alphabetical order and I believe they will be listed in the right order.

Here's an example:


Instance.RegisterClientScriptFile("1", "NCCommon.js");
Instance.RegisterClientScriptFile("2", "MeetingNo.js");

Let me know if this helps.

 

Posted 9/13/2007 3:48:29 AMPost #1768
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Ah thanks, I will try out that solution immediately!

kind regards
Henrik Nielsen

--
Henrik Nielsen
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: kanika.jackson, Ken Champion

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 5:30pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 1.453. 10 queries. Compression Enabled.