Web User Control doesn't show up at page load

F

fh

Hello!
I use a that I include in code behind in a placeholder
in page_load:

-----------------
PlaceHolder2.Controls.Clear();
_DowntimeDetail= new MES.ascx.DowntimeDetails();
PlaceHolder2.Controls.Add(_DowntimeDetail);
------------------

but the control doesn't show up when I request the page
(the control is made of with textbox and label)

for a test I have added this little code in page_load
 
C

Curt_C [MVP]

fh said:
Hello!
I use a that I include in code behind in a placeholder
in page_load:

-----------------
PlaceHolder2.Controls.Clear();
_DowntimeDetail= new MES.ascx.DowntimeDetails();
PlaceHolder2.Controls.Add(_DowntimeDetail);
------------------

but the control doesn't show up when I request the page
(the control is made of with textbox and label)

for a test I have added this little code in page_load
------
PlaceHolder2.Controls.Add(new Button());
------

and this time it worked!! the button appeared???

What am I missing????

does the control work if you place it on the form from the IDE instead
of from code in a placeholder?
 
F

fh

Curt_C said:
does the control work if you place it on the form from the IDE instead
of from code in a placeholder?
Yes it work properly when dragged and dropped in the form with VS studio.
I tought about doing so, but i need to access the member of the control
and I haven't find a way to access the object 'control' in code behind

So i created it on page_load....
 
C

Curt_C [MVP]

fh said:
Yes it work properly when dragged and dropped in the form with VS studio.
I tought about doing so, but i need to access the member of the control
and I haven't find a way to access the object 'control' in code behind

So i created it on page_load....

you should be able to access any public member of that control from
code.. but that's a different story. Trying to see why the PlaceHolder
isnt' acessing it properly....

Hmmm... thinking...
 
C

Curt_C [MVP]

Try

PlaceHolder2.Controls.Clear();
PlaceHolder2.Controls.Add(new MES.ascx.DowntimeDetails());
 
F

fh

Curt_C said:
Try

PlaceHolder2.Controls.Clear();
PlaceHolder2.Controls.Add(new MES.ascx.DowntimeDetails());
Thanks for your help!
I tried it but it still doesn't work... :(

But to go around the pb, I could just drop it on the page
but How can I access it?
Because, I don't understand something:
if a had a button in my page with VS
the control appear in the code behind and i can access it easily.

how come if i do the same with a web user control
it doesn't appear anywhere else than in the design view?

Franck
 
C

Curt_C [MVP]

fh said:
Thanks for your help!
I tried it but it still doesn't work... :(

But to go around the pb, I could just drop it on the page
but How can I access it?
Because, I don't understand something:
if a had a button in my page with VS
the control appear in the code behind and i can access it easily.

how come if i do the same with a web user control
it doesn't appear anywhere else than in the design view?

Franck

Couple options.
Either make the button in the UC public, then you can access it from the
page containing it, or put the code in the codebehind of the UC
 
F

fh

Curt_C said:
Couple options.
Either make the button in the UC public, then you can access it from the
page containing it, or put the code in the codebehind of the UC
Ok But when I drop my UC in the page,
VS give it an ID
this same ID that i can't access in code behind
and that is not declared at all in the code behind class??
 
C

Curt_C [MVP]

Ok But when I drop my UC in the page,
VS give it an ID
this same ID that i can't access in code behind
and that is not declared at all in the code behind class??

the UC isnt declared? If so, just manually add the declaration.
 
F

fh

Curt_C said:
the UC isnt declared? If so, just manually add the declaration.

simple as that!

thank you very much for your help

for the place holder Someone found it out:
the place holder is calling the render on each of it's child control
so as UC inherits from System.Web.UI.UserControl
and not from System.Web.UI.Control

it miss the implementation of chilcontrol & render...
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top