locked
Not TypeOf ctrl Is RadioButtonList RRS feed

  • Question

  • User-944424728 posted

    Hello, the code below is postback if it's not a radiobuttonlist. I added "Or Not TypeOf ctrl Is CheckBoxList"  but it's not working like radiobuttonlist. Can you advise what is missing? thank you. "If Not TypeOf ctrl Is RadioButtonList Or Not TypeOf ctrl Is CheckBoxList" .

    --

    below postback is working if not radiobuttonlist

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

            If Page.IsPostBack Then

                Dim ctrl As Control = GetPostbackControl()

                If Not TypeOf ctrl Is RadioButtonList Then

                    GetPostbackControl.Focus()

     

                End If

            End If

    Tuesday, June 25, 2019 10:22 PM

All replies

  • User409696431 posted

    Did you mean "and", not "or"?

    The condition "not checkboxlist or not radiobuttonlist" will be true for a checkboxlist (it's not a radiobuttonlist), true for a radiobuttonlist (it's not a checkboxlist) and true for any other control (it's not a checkboxlist, it's not a radiobuttonlist).  Every postback control will get focus.

    Do you want the control to get focus if it's not a checkboxlist and it is also not a radiobuttonlist?  In that case you'd use  if not checkboxlist AND not radiobuttonlist.

    Tuesday, June 25, 2019 11:40 PM
  • User-944424728 posted

    Hello you mean "

    If Not TypeOf ctrl Is RadioButtonList or not checkboxlist Then

                    GetPostbackControl.Focus()

    ?? I think it has syntax error. thanks.

    Tuesday, June 25, 2019 11:57 PM
  • User409696431 posted

     I am not showing you the VB code, just the pseudo code logic.  You can write the code yourself.

    My point is that using an OR between your two NOT conditions will mean that test passes everything, so there is no point to having a condition at all.   I assume you meant to use AND in your condition.

    Wednesday, June 26, 2019 12:05 AM