Bubbling Up Events

Discussion in 'ASP .Net Web Controls' started by a, Nov 9, 2003.

  1. a

    a Guest

    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?
    a, Nov 9, 2003
    #1
    1. Advertising

  2. a

    MSFT Guest

    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.)
    MSFT, Nov 10, 2003
    #2
    1. Advertising

  3. a

    a Guest

    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

    "MSFT" <> wrote in message
    news:...
    > 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, Nov 10, 2003
    #3
  4. a

    MSFT Guest

    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.)
    MSFT, Nov 11, 2003
    #4
  5. a

    MSFT Guest

    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.)
    MSFT, Nov 13, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy

    C# UserControl Bubbling events

    Andy, Oct 27, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    29,710
  2. John
    Replies:
    1
    Views:
    474
  3. =?Utf-8?B?RGFsZQ==?=

    Internal ASP.Net error bubbling events

    =?Utf-8?B?RGFsZQ==?=, Apr 11, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    471
    Steven Cheng[MSFT]
    Apr 14, 2006
  4. Javi

    Composite Controls and Bubbling events

    Javi, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    164
  5. Anonymous Poster

    Bubbling up custom events in datagrid

    Anonymous Poster, Jan 25, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    152
    Anonymous Poster
    Jan 25, 2005
Loading...

Share This Page