Link to home
Start Free TrialLog in
Avatar of bdb12
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?
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

Open in new window

Avatar of dinomix
dinomix

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.
Avatar of bdb12

ASKER

ok I cant find an attribute of Name for textboxs....

ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bdb12

ASKER

Ah I didnt know they where lost....that makes sense....I'll try out that code now and get back to you. Thx
Avatar of bdb12

ASKER

Still working on this....home time now so will get into it tomorrow....thx
Avatar of bdb12

ASKER

Thank you