My ajax user server control implements IScriptControl:
- GetScriptReferences
- GetScriptDescriptors
The first method sends javascript files, the second creates javascript objects based on some send files earlier .js.
In my "AssembleyInfo" file, I added the lines and marked .js files in the "Properties" in the "Properties":
// this allows access to this files [assembly: WebResource("ProjectName.file1.js", "text/javascript")] [assembly: WebResource("ProjectName.file2.js", "text/javascript")]
Here is the implementation of IScriptControl:
public IEnumerable<ScriptReference> GetScriptReferences() { yield return new ScriptReference("ProjectName.file1.js", this.GetType().Assembly.FullName); yield return new ScriptReference("ProjectName.file2.js", this.GetType().Assembly.FullName); } public IEnumerable<ScriptDescriptor> GetScriptDescriptors() { ScriptControlDescriptor descriptor = new ScriptControlDescriptor("ProjectName.file1", this.ClientID); //adding properties and events (I use "AnotherName" on the safe side to avoid potentional namespace problems ScriptControlDescriptor descriptor2 = new ScriptControlDescriptor ("AnotherName.file2", this.ClientID); //adding properties and events yield return descriptor; yield return descriptor2; }
Here are parts of my .js files:
first file
Type.registerNamespace("ProjectName"); ProjectName.file1 = function (element) { ....... ....... } ProjectName.file1.registerClass('ProjectName.file1', Sys.UI.Control); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
second file
Type.registerNamespace("AnotherName"); AnotherName.file2 = function (element) { ............ ............ } AnotherName.file2.registerClass('AnotherName.file2', Sys.UI.Control); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
WHY CREATES ONLY THE FIRST OBJECT?
yield return descriptor
My ASPX has JAVASCRIPT, WHICH SHOULD CREATE A SECOND.
IF I COMMENT ABOVE THE SECOND STATEMENT, THE SECOND CREATES NORMALLY.
source share