A
antonyliu2002
I am new to the .NET framework.
I know this has been discussed many times in this group. I also read
extensively here, however, I am in bad luck: none of the sample code
provided in this forum worked for me.
What I want to do is really simple.
I simply want to iterate through all controls of the current page and
create session objects for TextBoxes and CheckBoxes.
I tried this:
Sub CreateSessions()
Dim ctlObj As System.Web.UI.WebControls.WebControl
For Each ctlObj in Me.Controls
If ctlObj.GetType().ToString() =
"System.Web.UI.WebControls.TextBox" Then
Session(ctlObj.ToString()) = ctlObj.Text
End If
If ctlObj.GetType().ToString() =
"System.Web.UI.WebControls.CheckBox" Then
Session(ctlObj.ToString()) = ctlObj.Checked
End If
Next
End Sub
The error message I got:
Compiler Error Message: BC30456: 'Text' is not a member of
'System.Web.UI.WebControls.WebControl'.
Then what type should I assign to ctlObj? Thanks a lot!
I know this has been discussed many times in this group. I also read
extensively here, however, I am in bad luck: none of the sample code
provided in this forum worked for me.
What I want to do is really simple.
I simply want to iterate through all controls of the current page and
create session objects for TextBoxes and CheckBoxes.
I tried this:
Sub CreateSessions()
Dim ctlObj As System.Web.UI.WebControls.WebControl
For Each ctlObj in Me.Controls
If ctlObj.GetType().ToString() =
"System.Web.UI.WebControls.TextBox" Then
Session(ctlObj.ToString()) = ctlObj.Text
End If
If ctlObj.GetType().ToString() =
"System.Web.UI.WebControls.CheckBox" Then
Session(ctlObj.ToString()) = ctlObj.Checked
End If
Next
End Sub
The error message I got:
Compiler Error Message: BC30456: 'Text' is not a member of
'System.Web.UI.WebControls.WebControl'.
Then what type should I assign to ctlObj? Thanks a lot!