I'm developing a custom UserControl to inject JQuery hotkeys into a page declaratively on the server side. Here's the control (the important parts anyway):
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("HotKeys"),
ParseChildren(true, "HotKeys"),
ToolboxData("<{0}:HotKeysControl runat=\"server\"> </{0}:HotKeysControl>")]
public partial class HotKeysControl : System.Web.UI.WebControls.WebControl
{
private string crlf = Environment.NewLine;
public List<HotKey> _HotKeys;
public HotKeysControl()
{
if (_HotKeys == null)
{
_HotKeys = new List<HotKey>();
}
// if I uncomment this line, script is injected into the page
// _HotKeys.Add(new HotKey("ctrl+r","thisControl"));
}
[
Category("Behavior"),
Description("The hotkeys collection"),
DesignerSerializationVisibility(
DesignerSerializationVisibility.Content),
Editor(typeof(HotKeyCollectionEditor), typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerDefaultProperty)
]
public List<HotKey> HotKeys
{
set { _HotKeys = value; }
get { return _HotKeys; }
}
Here's the .aspx code:
<%@ Register Assembly="MyCompany.ProductName.WebControls" Namespace="MyCompany.ProductName.WebControls" TagPrefix="uc" %>
...
<uc:HotKeysControl ID="theHotkeys" runat="server" Visible="false">
<uc:HotKey ControlName="firstControl" KeyCode="ctrl+1" />
<uc:HotKey ControlName="thirdControl" KeyCode="ctrl+2" />
</uc:HotKeysControl>
Nothing happens, as if no HotKeys objects are being added to the property collection. What Am I doing wrong? If I uncomment out the line above and "manually" add items, it works. It's something about how I'm declaratively adding hotkeys to the page.
Any ideas?