Hello again @rmelancon!
I'm afraid using the
UserControlLoader component will add dynamics to the page that will disallow directly wiring events to the component. But you can fairly simplify the code for something that works with another approach that might just work for you!
The catch is to use Direct Methods instead. It will save you the trouble of getting the extra parameters by extending the
DirectEventArgs class with specialized code. Here is the sample above rewritten to use this approach:
ASPX markup:
61701-2-page.aspx
<%@ Page Language="vb" %>
<%@ Register Src="61701-2-userControl.ascx" TagName="ComboControl" TagPrefix="uc" %>
<script runat="server">
<Ext.Net.DirectMethod()>
Sub QuickSearch_Selected(selectedValue As String)
Ext.Net.X.AddScript("alert('quicksearch DirectMethod select event triggered with value: " & selectedValue & "');")
End Sub
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager" runat="server" />
<ext:Panel runat="server" Title="Event wired" Height="100" Width="400" Border="true">
<Content>
<uc:ComboControl ID="QuickSearch" runat="server" />
</Content>
</ext:Panel>
<ext:Panel runat="server" Title="Now works too!" Height="100" Width="400" Border="true">
<Items>
<ext:UserControlLoader runat="server" ID="QuickSearchExt" Path="61701-2-userControl.ascx" UserControlID="QuickSearchInner" />
</Items>
</ext:Panel>
</div>
</form>
</body>
</html>
Custom Control ASCX markup:
61701-2-userControl.ascx
<%@ Control Language="vb" %>
<ext:ComboBox
ID="Results"
runat="server"
FieldLabel="Select a single item"
DisplayField="Text"
LabelWidth="130"
QueryMode="Local"
TypeAhead="true">
<Items>
<ext:ListItem Text="TestingText1" Value="1" />
<ext:ListItem Text="Text" Value="2" />
<ext:ListItem Text="Text3" Value="3" />
</Items>
<Listeners>
<%-- Only makes the call if the direct method is defined on the current page. --%>
<Select Handler="if (App.direct && App.direct.QuickSearch_Selected) App.direct.QuickSearch_Selected('testing');" />
</Listeners>
</ext:ComboBox>
Notice there's no need for specific/static code behind anymore in this approach. At least as far as this code sample is concerned, this significantly simplifies the code. You can, instead of using a long
Handler= in your listener, bind a
Fn= and ensure you have this javascript function defined on the main page. This will allow you to draw more complex code (to fetch the parameter you want to pass to code behind, for example) with syntax highlighting in Visual Studio and nicer debugging either with Visual Studio or browser's developer tools.
If you are really requiring a solution where you hardwire the event to code behind, I'm afraid we have a deadlock here:
- using toolbar or menus is not compatible with the
Content blocks. Must use
Items instead.
- wrapping the
Content block under a Panel or Container inside toolbar or menus'
Items block breaks the hit box on menus at least
- to use a custom control in an
Items block, you need the
UserControlLoader component wrapper.
- the
UserControlLoader component adds dynamics to the page which renders code behind event wiring not feasible (at the least) to be implemented.
The references are these three posts in the forums:
-
Daniil, Aug 19, 2015 (which references the other two)
-
Vladimir, Jun 24, 2011
-
Daniil, Mar 20, 2013
There may be more if you do a search for
UserControlLoader in the forums but, I believe at least the last two above suffice.
Hope this helps!