bdb12
asked on
Aceessing controls in a Panel
I dynamically create some controls at runtime and add them into a panel.
Later on, I try to access those controls in a different function, butI get a null object error
Does anybody know what Im doing wrong?
Later on, I try to access those controls in a different function, butI get a null object error
Does anybody know what Im doing wrong?
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Dim TextBox1 As New TextBox
TextBox1.ID = "a"
TextBox1.Style("Position") = "Absolute"
Panel1.Controls.Add(TextBox1)
end sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim txt As TextBox = New TextBox()
txt = Panel1.FindControl("a") 'crash here
Label1.Text = txt.Text
end sub
Instead of setting textbox.id set textbox.name = "a".
Also, try accessing panel1 by preceeding with me. So me.panel1.findcontrol("a") .
My previous post is incorrect by the way, i confused with another method.
My previous post is incorrect by the way, i confused with another method.
ASKER
ok I cant find an attribute of Name for textboxs....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah I didnt know they where lost....that makes sense....I'll try out that code now and get back to you. Thx
ASKER
Still working on this....home time now so will get into it tomorrow....thx
ASKER
Thank you