Jul 28, 2011, 12:19 PM
[CLOSED] Event handlers on controls inside a UserControl that was added dynamically
I have a Page that has two tabs, when you click on the second tab it dynamically loads a user control (assigns ID="TestChild") with a select drop down control, into the tab. The select box (ID=FirmViewBySelect) has a directevent for the "select" event. The loading of the control works fine but when you select an item from a drop down, you get an error saying "the control with ID 'TestChild_FirmViewBySelect' not found. So in the dynamic loading of the control it is assigning a new control ID to the select box. So I kind of understand what is happening but not sure how to fix it. The "parent" page is PerformanceTest2.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="PerformanceTest2.aspx.vb" Inherits="WAP.Web.Advisor.PerformanceTest2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TabPanel ID="myPanel" runat="server" Height="200" Border="false" >
<Items>
<ext:Panel ID="PerformancePanel" runat="server" Title="Performance" Header="false" Border="false">
<TopBar>
<ext:Toolbar ID="Toolbar4" runat="server">
<Items>
<ext:Button ID="ButtonRobb" runat="server" Icon="PlayGreen" >
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:Panel>
<ext:Panel ID="SummaryPanel" runat="server" Title="Firm Summary" Height="200" Border="TRUE">
<Content></Content>
<DirectEvents>
<Activate OnEvent="SummaryPanel_Activate">
<EventMask ShowMask="true" Msg="Loading Panel" Target="Page" />
</Activate>
</DirectEvents>
</ext:Panel>
</Items>
</ext:TabPanel>
</form>
</body>
</html>
code behind:Imports Ext.Net
Public Class PerformanceTest2
Inherits System.Web.UI.Page
Protected Sub SummaryPanel_Activate(ByVal sender As Object, ByVal e As DirectEventArgs)
Dim fs = Page.LoadControl("~/TestChild1.ascx")
fs.ID = "TestChild"
SummaryPanel.ContentControls.Add(fs)
SummaryPanel.UpdateContent()
End Sub
End Class
child control: TestChild1.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TestChild1.ascx.vb" Inherits="WAP.Web.Advisor.TestChild1" %>
<ext:Panel ID="SummaryPanel" runat="server" Border="false" Height="200">
<TopBar>
<ext:Toolbar ID="ToolbarFirmSummary" runat="server" HideBorders="true">
<Items>
<ext:ButtonGroup ID="ButtonGroup2" runat="server" Title="View By" Height="68">
<Items>
<ext:TableLayout ID="TableLayout3" runat="server" Columns="3">
<Cells>
<ext:Cell>
<ext:SelectBox ID="FirmViewBySelect" runat="server" Editable="false" Width="185" ValueField="myID" DisplayField="myDescription">
<Store>
<ext:Store ID="StoreFirmViewBy" runat="server">
<Reader>
<ext:JsonReader IDProperty="myID">
<Fields>
<ext:RecordField Name="myID" />
<ext:RecordField Name="myDescription" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="FirmViewBy_Select">
<EventMask ShowMask="true" Msg="Loading Related Views" Target="Page" />
</Select>
</DirectEvents>
</ext:SelectBox>
</ext:Cell>
<ext:Cell>
<ext:Button ID="Button_FirmExecute" runat="server" Text="Execute" Disabled="true" Icon="PlayGreen" Height="38" Width="90">
<DirectEvents>
<Click OnEvent="Button_FirmExecute_Click">
<EventMask ShowMask="true" Msg="Gathering Data" Target="Page" />
</Click>
</DirectEvents>
</ext:Button>
</ext:Cell>
</Cells>
</ext:TableLayout>
</Items>
</ext:ButtonGroup>
</Items>
</ext:Toolbar>
</TopBar>
</ext:Panel>
code behind:Imports Ext.Net
Public Class TestChild1
Inherits System.Web.UI.UserControl
Protected Sub FirmViewBy_Select(ByVal sender As Object, ByVal e As DirectEventArgs)
End Sub
Protected Sub Button_FirmExecute_Click(ByVal sender As Object, ByVal e As DirectEventArgs)
End Sub
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
Dim someData As New Collection
Dim xdata As New testData
With xdata
.myID = 1
.myDescription = "One"
End With
someData.Add(xdata)
StoreFirmViewBy.DataSource = someData
StoreFirmViewBy.DataBind()
End Sub
Private Class testData
Private _myID As Integer
Public Property myID() As Integer
Get
Return _myID
End Get
Set(ByVal value As Integer)
_myID = value
End Set
End Property
Private _myDescription As String
Public Property myDescription() As String
Get
Return _myDescription
End Get
Set(ByVal value As String)
_myDescription = value
End Set
End Property
End Class
End Class
Last edited by Daniil; Aug 02, 2011 at 2:03 PM.
Reason: [CLOSED]