Hi all,
I'm wondering if it's possible to add an Array as property of a ScriptControlDescriptor.
Adding line number 55 in the following code results in the following error.
Error:
Cannot get inner content of MasterHead because the contents are not literal.
Code:
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10 using System.Collections.Generic;
11
12 using AjaxControlToolkit;
13
14 namespace OrganizerControls {
15 public class Organizer : Control, IScriptControl {
16 private ScriptManager sm;
17 private List _arrLiterals;
18
19 public Organizer(){
20 _arrLiterals = new List();
21 }
22 protected override void OnInit(EventArgs e) {
23 base.OnInit(e);
24 }
25 protected override void OnPreRender(EventArgs e) {
26 if (!this.DesignMode) {
27 sm = ScriptManager.GetCurrent(Page);
28
29 if (sm == null)
30 throw new HttpException("A ScriptManager control must exist on the current page.");
31
32 sm.RegisterScriptControl(this);
33 }
34
35 foreach (Control c in this.Controls) {
36 if (c.GetType() == typeof(LiteralControl))
37 this._arrLiterals.Add((LiteralControl)c);
38 }
39 base.OnPreRender(e);
40 }
41 protected override void Render(HtmlTextWriter writer) {
42 if (!this.DesignMode)
43 sm.RegisterScriptDescriptors(this);
44
45 base.Render(writer);
46 }
47 protected virtual IEnumerable GetScriptReferences() {
48 ScriptReference reference = new ScriptReference();
49 reference.Path = ResolveClientUrl("~/_js/OrganizerControls.Organizer.js");
50
51 return new ScriptReference[] { reference };
52 }
53 protected virtual IEnumerable GetScriptDescriptors() {
54 ScriptControlDescriptor descriptor = new ScriptControlDescriptor("OrganizerControls.Organizer", this.ClientID);
55 descriptor.AddProperty("CollectionLiterals", this._arrLiterals.ToArray());
56
57 return new ScriptDescriptor[] { descriptor };
58 }
59 IEnumerable IScriptControl.GetScriptReferences() {
60 return GetScriptReferences();
61 }
62 IEnumerable IScriptControl.GetScriptDescriptors() {
63 return GetScriptDescriptors();
64 }
65 }
66 }
Hopefully someone can help me out.
Thanks!
Martijn van Mechelen
Solved the above with a different approach.
Added a string of ID's as a property, which is split to an Array in the .js file:
descriptor.AddProperty("LiterallIds", strLiteralIds);
Or does someone have a better suggestion?
No comments:
Post a Comment