Form View Controls Unaccessable
I have seen many posts, but never found a solution. My basic problem is accessing the controls inside the formview. As I understand, you can only access currentMode's controls. So lets say I want to access edit mode's control and I am in readonly mode, so what I am doing is during mode-changed event, i am trying to access a control in edit mode. But irony is, although it detects the mode has been changed to edit, but it still has readonly mode's editmode's controls in memory, instead of edit mode;s, which become available after page is rendered. So they are only available during page unload event (not even at prerender), when it becomes useless to access and modify control property, because it has already been rendered.
So does anybody know the solution to the problem?
Following is a function in which I am trying to access a couple of controls and I am calling it during mode-changed event:
Protected Sub addValueAttributeToPasswordTextBoxes()
Dim cntrl1 As Control
If fvContactDetail.CurrentMode = FormViewMode.Edit Then
For Each cntrl1 In fvContactDetail.Row.Controls
Dim SSN As TextBox = CType(cntrl1.FindControl("SSN"), TextBox)
Dim SSN_PWD As TextBox = CType(cntrl1.FindControl("SSN_PWD"), TextBox)
Dim SSN_Confirm_PWD As TextBox = CType(cntrl1.FindControl("SSN_Confirm_PWD"), TextBox)
If Not (SSN Is Nothing Or SSN_PWD Is Nothing Or SSN_Confirm_PWD Is Nothing) Then
Dim SSN_PWD_Value As String = SSN_PWD.Attributes.Item("Value")
Dim SSN_PWD_Confirm_Value As String = SSN_Confirm_PWD.Attributes.Item("Value")
If SSN_PWD_Value Is Nothing Then
SSN_PWD.Attributes.Add("Value", SSN.Text)
Else
SSN_PWD.Attributes.Item("Value") = SSN.Text
End If
If SSN_PWD_Confirm_Value Is Nothing Then
SSN_Confirm_PWD.Attributes.Add("Value", SSN.Text)
Else
SSN_Confirm_PWD.Attributes.Item("Value") = SSN.Text
End If
SSN = Nothing
SSN_PWD = Nothing
End If
Next
End If
End Sub
Thanks
Mehranian
|