help.net

<font size="2"><br />Musing on .Net</font>

  • Nasty bug !

    I start on a bad day today, with a nasty bug I can't figure out what's wrong.
     
    I loop through a series of controls using Typeof to populate a form with different values from the database.
    The control (D2) is embedded in another control D. This code is from my mainpage where I populate the forms.
    PageD2ctl is declared as a Panel, child of D2.

    The problem is that when the control is a Radiobutton, and I am sure it is(just checked in debug mode), my code enter correctly in the test, but it's going also in the Checkbox test, like suddenly my Radiobutton is now typed as a Checkbox.

    I spent sometime on that, but absolutly no clue about what's going on. I tried everything, transforming my nice ElseIf in If then loop, nothing at all.
     
    If anyone has an idea ?
     
     Dim MyCtl2 As Control
                        For Each MyCtl2 In PageD2ctl.controls
     
                            If Not (TypeOf MyCtl2 Is LiteralControl) Then
                                If MyCtl2.ID = dtr("id_q") Then
                                    If TypeOf MyCtl2 Is TextBox Then
                                        Dim ThisTextbox As TextBox = CType(PageD2ctl.findcontrol(dtr("id_q")), TextBox)
                                        ThisTextbox.Text = dtr("answer")
                                    Elseif TypeOf MyCtl2 Is RadioButton Then
                                        Dim ThisRadiobox As RadioButton = CType(PageD2ctl.findcontrol(dtr("id_q")), RadioButton)
                                        If LCase(dtr("answer")) = "true" Then
                                            ThisRadiobox.Checked = True
                                        End If
                                   
    '-- and there after succesfully finish the previous test if it's a radiobutton the code enter in the Checkbox one !

                                    ElseIf TypeOf MyCtl2 Is CheckBox Then
     
                                        Dim ThisCheckbox As CheckBox = CType(PageD2ctl.findcontrol(dtr("id_q")), CheckBox)
                                        If LCase(dtr("answer")) = "true" Then
                                            ThisCheckbox.Checked = True
                                        End If
                                    End if

                             End If
                           End if
                        Next
    UPDATE:
    I found this solution that I share now:

    This confirms (for me) that something wrong there with the Controls.

    Instead of using an Elseif structure, I write a Select..Case structure like this (Myctl is the ontrol to test):

    select case lcase(Myctl.gettype.tostring)
    case "system.web.ui.webcontrols.textbox"
    .. Mycode
    case "system.web.ui.webcontrols.radiobutton"
    .. MyCode
    case "system.web.ui.webcontrols.checkbox"
    .. Mycode
    end select

  • Database Challenge

    I have to do some coding for Scoilnet this week-end, but I have to complete another database challenge for another project.

    Ok , basics elements first:

  • I am a green

    I am not sure how to take this one, I don't feel really being an ecowarrior, maybe hippie a little bit man ;-)

  • Even more USB-powered gadgets

    Read from Gizmodo :-))))

    The USB-powered gadgets keep coming! To add to the USB toothbrush and USB hot cup, there's now a USB heating pad (to keep you warm at night) and a USB mini hot-plate that keeps your drink warm while you're working hard! Actually, given how cold it's been here in New York lately, that heating pad sounds pretty good right about now.


    Read - USB heating pad
    Read - USB hot-plate
    Read USB Toothbrush

    It's look like it was created by some mad big boss who wants to chain his developers to their computers ;-)
    Soon the USB waterbed ;-))