Problem in handling events of composite controls.

A

Abhishek

Hi,

I am developing a composite control. I am facing problem in
CreateChildControls method. I’m giving a brief description of my problem.

Problem1 : Suppose I have a dropdown list. This list contains two items say
item1 and item2. Now on the select index change event of this dropdownlist I
am binding different data sources to my control. It is working perfectly fine
when I am chaging the item of the drop down first time, it is calling
CreateChildControls methods as I’m binding my control (Mycompoite.DataBind).
But now after that how many items we change it is calling CreatChildControls
and no action is going to perform in DataBind method. In order to overcome
this I’m overriding the Base Class DataBind method and here I’m calling
CreateChildControls method like this :

Public Overrides Sub DataBind()
CreateChildControls()
MyBase.DataBind()
End Sub

I want to know calling createchildcontrols in DataBind of base class is good
approach or not. Is there anyother way for doing the same.

Problem2: Here I am going to provide two sample piece of code. Both of them
have the same approach but one is working and another one is’t.


‘This one is working
Protected Overrides Sub CreateChildControls()
For Inc As Integer = 0 To 3
Img = New ImageButton
AddHandler Img.Click, New ImageClickEventHandler(AddressOf ImageClick)

Me.Controls.Add(Img)
Next Inc
MyBase.CreateChildControls()
End Sub

‘This one is’t working
Protected Overrides Sub CreateChildControls()


For TabCnt As Integer = 0 To DataSource.Tables.Count - 1

For Inc As Integer = 0 To
DataSource.Tables(TabCnt).Rows.Count - 1

Row = New TableRow
Dr = DataSource.Tables(TabCnt).Rows(Inc)

For IncCnt As Integer = 0 To Columns.Count - 1

If CType(Columns.Item(IncCnt), ArrayList).Item(0) =
"TemplateColumnArray" Then

For Item As Integer = 0 To
CType(CType(Columns.Item(IncCnt), ArrayList).Item(2),
ControlCollection).Count - 1
If TypeOf CType(CType(Columns.Item(IncCnt),
ArrayList).Item(2), ControlCollection)(Item) Is ImageButton Then

Img = New ImageButton
AddHandler Img.Click, New
ImageClickEventHandler(AddressOf ImageClick)

Me.Controls.Add(Img)



End If

Next


End If


Next IncCnt

Next Inc

Next TabCnt
MyBase.CreateChildControls()
End Sub

Now in both code you can see I am adding an handler on click. In the first
code the handler is working, but in the second example it is not working..
Although both of the code is creating three image controls..and they are
visible to me at runtime. Can anyone suggest me what is the reason behind
that. I spend a lot of time in investigation of this. When I’m placing break
point on the code I m finding that control is associate with the event but it
is not working.

Thanks,
Abhishek
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top