Events from dynamic checkboxes sometimes handled the wrong way

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • galien8@zonnet.nl

    Events from dynamic checkboxes sometimes handled the wrong way

    Dear Newsgroup Readers,

    I have a problem with dynamic controls, in a DotNetNuke module, and
    event handlers in VB.NET ASP.NET 2.0. Events are firing and being
    handled, sometimes good but also sometimes in a wrong way. I always
    unchecked the first of the list (See Also Source Code Below):

    CheckBox1 sender ID = D0
    CheckBox2
    CheckBox3
    CheckBox4
    CheckBox5

    CheckBox2 sender ID = D1
    CheckBox3
    CheckBox4
    CheckBox5

    CheckBox2 sender ID = D0
    CheckBox4
    CheckBox5

    CheckBox4 sender ID = 1
    CheckBox5

    CheckBox5 CheckChanged event does not fire first time must uncheck
    again

    (NB: ID of the sender should always be D0)

    And so on. The last remaining one does not fire an event and must be
    unchecked again to be removed

    I tried everything, code examples on the internet are more or less the
    same with mine.
    (I tried EnableViewState false and true for page, panel and dynamic
    checkboxes)

    Any ideas what the problem is? I do not believe that it is one of
    those hard to debug asynchrone bugs, because the code is so simple!

    PLEASE HELP!

    Kind regards,

    Johan van der Galien.

    Code snipped:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    Dim MyCustomIngredi ents As New List(Of CustomIngredien ts)
    Dim MyDBItemCheckBo x As CheckBox

    MyCustomIngredi ents =
    MyDataBase.Sele ctAllCustomIngr edients(UserId)

    Me.DBMaintenanc ePanel.Controls .Clear()

    Dim I As Integer
    For I = 0 To MyCustomIngredi ents.Count - 1
    MyDBItemCheckBo x = New CheckBox
    MyDBItemCheckBo x.AutoPostBack = True
    MyDBItemCheckBo x.Checked = True
    'MyDBItemCheckB ox.EnableViewSt ate = False
    MyDBItemCheckBo x.ID = "D" & I.ToString
    MyDBItemCheckBo x.Text =
    MyCustomIngredi ents(I).Descrip tion
    AddHandler MyDBItemCheckBo x.CheckedChange d, AddressOf
    ADBItemCheckCha nged
    Me.DBMaintenanc ePanel.Controls .Add(MyDBItemCh eckBox)
    Me.DBMaintenanc ePanel.Controls .Add(New
    LiteralControl( "<br />"))
    Next
    End Sub

    Public Sub ADBItemCheckCha nged(ByVal sender As Object, ByVal e
    As EventArgs)
    Me.IngredientsP anel.Visible = False
    Me.DBMaintenanc ePanel.Visible = True
    Me.OUTPUTLabel. Visible = False
    Me.ItemsDropDow nList.SelectedI ndex = 0
    Me.DBMaintenanc eButton.Visible = False
    Me.FinishDBMain tenanceButton.V isible = True
    Me.ADDButton.En abled = False

    Dim MyDBItemCheckBo x As CheckBox = DirectCast(send er,
    CheckBox)

    Dim MyDataBase As New SqlDataProvider
    Dim MyCustomIngredi ents As New List(Of CustomIngredien ts)

    '1) Load list of items from database
    MyCustomIngredi ents =
    MyDataBase.Sele ctAllCustomIngr edients(UserId)

    '2) Remove unchecked item from database

    MyDataBase.Dele teCustomIngredi ent(MyCustomIng redients(CInt(M yDBItemCheckBox .ID.Trim("D"))) )
    End Sub

    PS: I am using Visual Web Developer 2005 Express.
Working...