Problem Adding Controls

L

loureiro

Hello,

I seem to be having a problem loading a div tag with a control. here is what
I am doing:

Dim oObjCheckBox As CheckBox = New CheckBox()

oObjCheckBox.ID = "chkTestControl"

oObjCheckBox.Text = "Test Control"

outputList.Controls.Add(oObjCheckBox)

i do this inside a sub routine. now my problem is that when i try to access
that control outside the sub routine i created it in it doesnt exist. any
ideas why?
 
S

Steve C. Orr [MVP, MCSD]

It looks like you're declaring the control (using the Dim statement) as a
private variable inside the subroutine.
Therefore the variable is out of scope in other subroutines.
Try defining it as a public variable of the page class.
 
L

loureiro

I dont think thats the problem. I tried it and it still gives me a problem
with it disappearing when I go into a new subroutine. Could it have anything
to do with me clicking a button and submitting the form again? I tried using
the ispostback but it didnt seem to make a difference. I am trying to create
this without using any classes. just using vbscript. any other suggestions?
 
S

Steve C. Orr [MVP, MCSD]

Oh, yes. You didn't previously mention that you were doing a postback in
between.
When you create a control dynamically, you are expected to recreate it upon
each postback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top