Control state not reading properly...

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Okay. Strange situation.

I have a mobile application that I am developing. Part of it displays a dynamic list of questions with checkmarks, based on a SQL Query. No big deal. All question controls are created in Page_Init, like so:

Code:
   selDynamic = New System.Web.ui.MobileControls.SelectionList
   selDynamic.ID = "Check" & Trim(Str(LoopVar)) & "-" & QuestionArray(10, LoopVar)
   selDynamic.SelectType = MobileControls.ListSelectType.CheckBox
   selDynamic.Font.Name = "Arial"
   selDynamic.Font.Size = MobileControls.FontSize.Small
   If Len(Trim(QuestionArray(7, LoopVar))) > 0 Then
 	 If QuestionArray(10, LoopVar) = 0 Then						 ' Checked
   		  EmpInits = " - " & QuestionArray(13, LoopVar)
   		  selDynamic.ForeColor = Color.Red
   	 Else
   		  EmpInits = ""
   		  selDynamic.ForeColor = Color.Black
   	 End If
 	 selDynamic.Items.Add(QuestionArray(7, LoopVar) & ". " & QuestionArray(4, LoopVar) & EmpInits)
   Else
   	 selDynamic.Items.Add(QuestionArray(4, LoopVar))
   End If
   If QuestionArray(10, LoopVar) = "0" Then selDynamic.SelectedIndex = 0
   frmDynamic.Controls.Add(selDynamic)

It creates the controls perfectly.

I have a dropdown list so the user can select their initials from a list

I have a button on the page to save responses back to the database. Good.

Now, here is the bizarre part. When you check off a question and save the first time, it works fine. If you then, without leaving the page, select the same question (un-check the box), it doesn't properly read the selectedindex of the control. I cannot explain it.

Here is the code for the button:

Code:
 Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
 lblDynamicDebug.Text = "Before Click: " & CType(frmDynamic.Controls.Item(19), MobileControls.SelectionList).SelectedIndex.ToString
  SaveChecklist()
  End Sub

Index 19 is the first question on the page.

Since there is only a selection list in Mobile, it is a selection list of type CheckBox, and there is only one element in the list.

Therefore, if the checkbox is checked, the resulting .SelectedIndex is 0. If the checkbox is NOT checked, the resulting .SelectedIndex is -1.

If a question is checked, then the button is clicked, I get
BeforeClick: 0
Now, un-checkikng the box and clicking the button again gives this:
BeforeClick: 0
Same result. Now for more bizarre happiness. The checkbox goes BACK to CHECKED! Un-check it again and click, and you get this:
BeforeClick: -1
I have no idea why it won't properly read the state of the checkbox after it is saved. I have no ideas.

HELP!!!!!!

Kahuna
 
Back
Top