Bubbling Up Events

A

a

Hi,

I have a CustomControl that is essentially a WebControls.Table (TEKTable).
You tell it how many columns, and it renders UserControls (passed in via an
ArrayList) in that number of columns, and however many rows it takes.

My UserControls typically have buttons on them. I can't seem to get the
event to bubble up. TEKTable is in a UserControl project, so it won't
always be aware of the types located in the web app. SO, when I try to add
an event handler to the event of the UserControl, it won't do it. And I
can't do a CType, because I don't want to be able to use this table to host
many different controls.

How can / should I set this up? Do I need a TEKTable that is designed to
hold each diff. UserControl I will ever use?
 
M

MSFT

Hello,

As my understanding, your custom control "TEKTable" is like a DataGrid web
control in ASP.NET. Is this correct? To get a children control in datagrid,
we can use "FindControl" method with the children controls's name. And then
get its type with its GetType method, to determine if it is a Button or
TextBox. To add a eventhandler, we can use AddHandler method. Can these
methods work with your custom control?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
A

a

Here is my code for TEKTable:

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:TekTable
runat=server></{0}:TekTable>")> Public Class TekTable

Inherits Control
Implements INamingContainer


Dim _text As String
Dim intMaxCols As Integer
Dim intMaxWidth As Integer
Dim alUC As New ArrayList

Public Event evtAddToCart()
Public Event Click As EventHandler

<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
EnsureChildControls()
Return _text
End Get

Set(ByVal Value As String)
EnsureChildControls()
_text = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue("3")> Property
myMaxCols() As Integer
Get
EnsureChildControls()
Return intMaxCols
End Get
Set(ByVal Value As Integer)
EnsureChildControls()
intMaxCols = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue("800")> Property
myMaxWidth() As Integer
Get
EnsureChildControls()
Return intMaxWidth
End Get
Set(ByVal Value As Integer)
EnsureChildControls()
intMaxWidth = Value
End Set
End Property
<Bindable(True), Category("Appearance"), DefaultValue("")> Property
myUC() As ArrayList
Get
Return alUC
End Get
Set(ByVal Value As ArrayList)
alUC = Value
End Set
End Property


Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
ensurechildcontrols()
Me.RenderChildren(output)
End Sub


Protected Overrides Sub CreateChildControls()
If Me.alUC.Count <> 0 Then

Dim tbl As New Table

Dim r As TableRow
Dim c As TableCell
Dim int As Integer
Dim booAdded As Boolean = False
Dim i As Integer = 1

For int = 0 To alUC.Count - 1
booAdded = False
If i = 1 Then
r = New TableRow
End If

c = New TableCell
c.VerticalAlign = VerticalAlign.Top

Dim uc As ucCookie = alUC.Item(int)

c.Controls.Add(uc)
r.Cells.Add(c)
If i = intMaxCols Then
tbl.Rows.Add(r)
booAdded = True
i = 0
End If
i += 1
tbl.Rows.Add(r)
Next

If booAdded = False Then
tbl.Rows.Add(r)
End If

Me.Controls.Add(tbl)

End If
End Sub
End Class

I have 2 issues: First, I want to perform an action when a Button is
clicked on the ucCookie control. I can't get it to work. Second, I want to
avoid this line:
<<Dim uc As ucCookie = alUC.Item(int)>>
that way I can use the TEKTable control to display any number of columns of
other controls I want.

Does a DataGrid allow me to do this (I don't need TEKTable)?

I can't get the dynamically created UserControl added to a CustomControl to
handle its own events.

Please help.

Kevin
 
M

MSFT

Hi Kevin,

Is "ucCookie" also a custom web control which has a ASP.NET button on it?
If so, you may add the code in the "ucCookie" to handle the click event of
the button. For question 2:

Dim uc As ucCookie = alUC.Item(int)

You may change it to:

Dim uc As Control = alUC.Item(int)

so that is can accept any type of ASP.NET web control.


Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

MSFT

Hi Kevin,

Is "ucCookie" also a custom web control which has a ASP.NET button on it?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top