Problem with Eventhandlers dynamicly created MobileControls

K

Kristof Pauwels

Hellow, I have this peace of code from an ASP.NET page for a Mobile device,
but i have a small problem.
In this first SUB I dynmamicly create a MobileControls.Command.
I add an EventHandler to this Control

But when I click on this button, the only thing I notice is there is a post,
but the eventhandler is never fired. :-(

Is it possible that a dynmicly created control looses his event after an
PostBack??

If so, or if you know where my problem is, I would be gratefull.

Thanks in advance.


Private Sub PupulateFormWithLinks(ByVal CurrentFormIndex As Integer)
Dim DataRow As DataRow
For Each DataRow In TabsDataTable.Rows
Dim TabIndex As Integer = DataRow.Item("TabIndex")
'No linkbutton on the page that reffers to itself
If TabIndex <> CurrentFormIndex Then
Dim CMDLink As New MobileControls.Command
CMDLink.Text = "-" & TabIndex & "-"
CMDLink.CommandName = "CMDLink_OnClick"
CMDLink.CommandArgument = TabIndex
CMDLink.BreakAfter = False
CMDLink.ID = "CMDLink" & TabIndex
AddHandler CMDLink.Click, AddressOf OnClick

Form1.Controls.Add(CMDLink)
End If
Next
Form1.DataBind()
End Sub

'EventHandler for the clicks on the CommandControl, but this fucker is
never fired ;-(
Sub OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim CurrentFormIndex As Integer = Convert.ToInt16(CType(sender,
MobileControls.Command).CommandArgument)
Form1.Controls.Clear()
PopulateFormWithFields(Accountno, 1, CurrentFormIndex
PupulateFormWithLinks(CurrentFormIndex)

ActiveForm = Form1
End Sub
 
R

Rahul Singh

Kristof,

Yes unless you declare that control as a protected member and then
initialize it afterwards.
I had the same problem and this seemed to solve it. You should also take a
look at how
ASP.NET generates the classes at runtime. It uses a function called
ParseControl (which takes the string representation of a control
and adds it to the Page object you're working with)

Rahul Singh

anant systems, inc. | making information work for you

anantsystems.net | ioserver.net [Developer and Business .NET Hosting]
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top