Saturday, March 24, 2012

Session variable to formview

I would like to do the following :
Dim FV_Str As Object = Session("SesParFormView")
Dim Fv As FormView = FindControl(FV_Str)
I want to assign the content of session variable "SesParFormView" intoa formview variable, and subsequently try to find the formview withfindcontrol.Fv becomes "nothing". What now ?
Thanks in advance.
Maarten


Maarten_Issue wrote:

I would like to do the following :
Dim FV_Str As Object = Session("SesParFormView")
Dim Fv As FormView = FindControl(FV_Str)
I want to assign the content of session variable "SesParFormView" into a formview variable, and subsequently try to find the formview with findcontrol.Fv becomes "nothing". What now ?


FindControl finds the secified control in the Page Controlcollection. In your case you only assigned the session value to a local variable or object. So, it wouldnt be inside the Page control collection. Thats why it is returning null
Im trying to find an existing formview that has been saved in the localsession variable "SesParFormView". FindControl works fine if i put thecontents of the variable manually into it's id field. Also the compiler(VWD Beta 2) complains about not being able to convert "FV_Str" fromFormView to String. It also happens when i try to use the directcast ofctype functions.

Found the solution. See below:
Dim FV_Str As String = Session("SesParFormView")
Dim FV_Str2 As New FormView
If Not (IsNothing(FV_Str)) Then
FV_Str2.ID = FV_Str
Dim Fv As FormView = FV_Str2
If Not (IsNothing(Fv)) Then
Fv.DataSourceID = Nothing
Fv.Visible = False
End If
End If
Now I'm able to find a formview dynamically.
Maarten

Unfortunately the new created FormView "Fv" doesnt "bind" to the realFormView that resides on the form. :S It has no effect when I changethe "DataSourceID" to "Nothing"...What do I have to do to make it bindto the real FormView ? (Other than FindControl and CType)
Some help may be needed :S
Thanks !!
Maarten

0 comments:

Post a Comment