Hi Experts,
I have an ASP.NET app that I am building for user security in my current intranet. The problem Im having is I have a panel that dynamical grabs a list which I represent with a list of checkboxes. It populates the value of the checkboxes checked or unchecked correctly. The problem is when change some check value hit submit, I noticed that the db was not updated correctly and when the page came back I still had all of the "modified" changes on the page. This is odd as I requery and rebuild the textboxes upon and update. So in a nutshell I make changes hit post it is supposed to update the db and after updating it call the methods that rebuild the control and check or uncheck accordingly, but its not working. I have stepped through the code and I watch it setting up the controls correctly but renders the old page??
Here is a snippet to give you an idea :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
doProcedures()
Else
pnSecurity.Style.Add("disp
lay", "none")
indyDiv.Style.Add("display
", "none")
End If
End Sub
Private Sub doProcedures()
Dim rv As New CRIdal.retVal
Dim btn As String
Dim employeeID As String = rv.returnedVal(Request, "lbEmployees")
Dim empInfo As String()
Dim security As String()
Dim grpPolicy As String = rv.returnedVal(Request, "grpPolicy")
Dim scView As Boolean
btn = rv.whatButton(Request)
Call intialize()
Select Case btn
Case "btnSaveSecurity"
'Dim userid As Integer = rv.returnedVal(Request, CInt(txtUserID.Text))
Call getItemizedSecuritySelecte
d()
Call loadUserInfo()
Me.Controls.Add(New LiteralControl("<script>in
dyDivDispl
ay('indyDi
v', 'pnSecurity', 1);openSCSecDiv('cbSCView'
, 'pnSecurityBreakout')</scr
ipt>"))
end select
End sub
Private Function getItemizedSecurity(ByVal userID As String) As String()
Dim sqlState, errText As String
Dim reader As SqlDataReader
Dim sqlConn As New SqlConnection
Dim qdb As New CRIdal.queryDBase
Dim itemizedSecurity As String()
sqlState = "SELECT readOnly, scView, fiscalView, irTracking, scAll, officeAll, programsAll FROM mydb WHERE userID = " & userID
Try
If qdb.queryDbase(sqlState, sqlConn, reader, False, errText, ) Then
If reader.Read Then
ReDim Preserve itemizedSecurity(6)
itemizedSecurity(0) = reader.GetBoolean(0) 'ReadOnly
itemizedSecurity(1) = reader.GetBoolean(1) 'scView
itemizedSecurity(2) = reader.GetBoolean(2) 'fiscalView
itemizedSecurity(3) = reader.GetBoolean(3) 'IRTracking
itemizedSecurity(4) = reader.GetBoolean(4) 'scALL
itemizedSecurity(5) = reader.GetBoolean(5) 'officeALL
itemizedSecurity(6) = reader.GetBoolean(6) 'programsAll
qdb.closeConnections(reade
r, sqlConn)
Return itemizedSecurity
Else
qdb.closeConnections(reade
r, sqlConn)
End If
Return Nothing
Else
qdb.closeConnections(reade
r, sqlConn)
End If
Catch ex As Exception
qdb.closeConnections(reade
r, sqlConn)
End Try
End Function
Private Sub loadUserInfo()
Dim btn As String
Dim employeeID As String
Dim empInfo As String()
Dim security As String()
Dim grpPolicy As String
Dim scView As Boolean
Dim rv As New CRIdal.retVal
employeeID = rv.returnedVal(Request, "lbEmployees")
Call getEmployeeInfo(employeeID
, empInfo)
If Not empInfo Is Nothing Then
Call loadControls(empInfo, scView)
security = getItemizedSecurity(empInf
o(0)) 'Call procedure if individual security.
Call loadSCItemizedPanels(secur
ity)
Else
lblErrMessage.Text = "Employee found but is not registered. Please register employee and try again."
End If
End Sub
Private Sub loadSCSelection(Optional ByVal checkExisting As Boolean = False)
Dim sqlState, errText As String
Dim reader As SqlDataReader
Dim sqlConn As New SqlConnection
Dim qdb As New CRIdal.queryDBase
Dim i, j As Integer
Dim holdArray As String
Dim allCheck, allEditCheck As Boolean
Dim chkBox As CheckBox
Dim chkBox2 As CheckBox
Dim sc As String(,)
sqlState = "SELECT coordinator_last + ', ' + coordinator_first, coordinator_id FROM mydb WHERE status = 'active' order by coordinator_last"
Try
If qdb.queryDbase(sqlState, sqlConn, reader, False, errText, ) Then
If reader.HasRows Then
With pnSCSelection.Controls
.Add(New LiteralControl("<br><br>Se
rvice Coordinator Caseload<br><br>"))
.Add(New LiteralControl("<table border=1 width=90%><tr><td align=center>Edit</td>" & _
"<td align=center>Read</td>" & _
"<td align=center>SC Name</td></tr>"))
End With
'check here for all if checkExisting if yes set edit all flag
'/////////////////////////
//////////
//////////
//////////
/////
'chkBox2.Attributes.Add("o
nclick", "selectAll('" & chkBox2.ID & "', " & holdArray & ")")
While reader.Read
ReDim Preserve sc(1, j)
sc(0, j) = reader.GetString(0) 'SCName
sc(1, j) = reader.GetInt32(1) 'SCID
If holdArray = "" Then holdArray = sc(1, j) _
Else holdArray += ", " & sc(1, j)
j += 1
End While
If allExists("editAll") Then
allEditCheck = True
chkBox2 = createCheckBoxControl("cbE
dit", "", -1, -1, True, holdArray)
Else
chkBox2 = createCheckBoxControl("cbE
dit", "", -1, -1, False, holdArray)
End If
'-->
'check here for all if checkExisting if yes set all sc flag
'/////////////////////////
//////////
//////////
//////////
////
If allExists("scAll") Then
allCheck = True
chkBox = createCheckBoxControl("cbS
C", "", -1, -1, True, holdArray)
Else
chkBox = createCheckBoxControl("cbS
C", "", -1, -1, False, holdArray)
End If
With pnSCSelection.Controls
.Add(New LiteralControl("<tr><td align=center>"))
.Add(chkBox2)
.Add(New LiteralControl("</td><td align=center>"))
.Add(chkBox)
.Add(New LiteralControl("</td><td>&
nbsp; 
;"))
.Add(New LiteralControl("All SC"))
.Add(New LiteralControl("</td></tr>
"))
'.Add(New LiteralControl("<br>"))
'-->
End With
Dim test As String = sc.GetUpperBound(1)
While i <= sc.GetUpperBound(1)
'check here for sc security here if checkExisting
'/////////////////////////
//////////
//////////
///
Dim scName As String = sc(0, i)
Dim scid As Integer = sc(1, i)
''check for edit
If Not allEditCheck Then
'Enters here if AllEditCheck=false
If secRowCheck("scSecFilter",
scid, "scid", "editRights") Then
'Check if row exists for edit in scSecFilter
chkBox2 = createCheckBoxControl("cbE
dit", "", scid, i, True)
chkBox = createCheckBoxControl("cbS
C", "", scid, i, True)
Else
'Edit Flag doesnt exist or row doesnt exist check read flag
chkBox2 = createCheckBoxControl("cbE
dit", "", scid, i)
If Not allCheck Then
If secRowCheck("scSecFilter",
scid, "scid", "readRights") Then
chkBox = createCheckBoxControl("cbS
C", "", scid, i, True)
Else
chkBox = createCheckBoxControl("cbS
C", "", scid, i)
End If
Else
chkBox = createCheckBoxControl("cbS
C", "", scid, i)
End If
End If
Else
chkBox2 = createCheckBoxControl("cbE
dit", "", scid, i, True)
'If Not allCheck Then
' If secRowCheck("scSecFilter",
scid, "scid", "readRights") Then
' chkBox = createCheckBoxControl("cbS
C", "", scid, i, True)
' Else
' chkBox = createCheckBoxControl("cbS
C", "", scid, i)
' End If
'Else
chkBox = createCheckBoxControl("cbS
C", "", scid, i, True)
'End If
End If
With pnSCSelection.Controls
.Add(New LiteralControl("<tr><td align=center>"))
.Add(chkBox2)
.Add(New LiteralControl("</td><td align=center>"))
.Add(chkBox)
.Add(New LiteralControl("</td><td>&
nbsp; 
;"))
.Add(New LiteralControl(scName))
.Add(New LiteralControl("</td></tr>
"))
i += 1
End With
End While
qdb.closeConnections(reade
r, sqlConn)
pnSCSelection.Controls.Add
(New LiteralControl("</table>")
)
Else
Response.Write("No Rows Returned:Line#827")
qdb.closeConnections(reade
r, sqlConn)
End If
Else
Response.Write("No Similar Records: Null condition ln:831")
qdb.closeConnections(reade
r, sqlConn)
End If
Catch ex As Exception
qdb.closeConnections(reade
r, sqlConn)
End Try
End Sub
I left some functions out but point being ... I step through the same code that is executed on load after i udate the db but the same control values are returned NOT the correct values from the DB? Is there a way to implicitly dispose of the panels that contain the checkboxes ....
A work around would be to response redirect it but Id rather not because that will require passing around more "ids" and I want to avoid if possible. Thanks in advance