user control declarations ignored

F

foldface

Hi
I have an odd problem with a user control.

- I have an asp page which holds a single usercontrol.
- On that user control I have a button and placeholder. When the button is
pressed I want a user control to loaded into the placeholder.
- I do this by having a flag which is set by the button logic. If in the
PreRender call the flag is set then the control is loaded. I do this in
the PreRender stage because I want to make sure the button postback
has occured (it has, checked in debugger)
- If I do this by explicitly constructing the user control, it doesn't
work (see below for details). If I do this using LoadControl it does.

The manner in which it doesn't work is odd. Basically it doesn't set
the declarations in the ascx file. I have traced through with a watch on the
'this' value. In the OnInit call I can see that the values haven't been set,
using LoadControl I can see they have been set.

- To be exact by declarations I mean statements like this in the ascx file

<asp:Calendar id="calendar" runat="server" Width="250px"></asp:Calendar>


A second complication is that for debugging I included this:

protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
}

I did this so I could see it was being called, also because after the first
line I would have expected the declarations to be setup. It only gets called
using the explicit construction method, not via LoadControl? I would have
expected it to be called for both. It is definately protected for both in the
Temporary ASP.Net file.

Any ideas?


Plus here are some observations with User Controls:
- Page_Load can be called more than once, the way around this seems to be
to use a method name other than Page_Load. I guess the framework includes
calls to this further in.
- using <!-- --> won't comment out code in an ascx page, <%-- --%> will

Thanks
F
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top