accessing .ascx data from .aspx

M

Martin Eyles

Hi,
I have a .aspx page which has a .ascx file included through the lines

<%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %>
and
<aspcustom:menu id="Menu1" runat="server"></aspcustom:menu>

both of these files have vb.net code behind.

I am processing some information from a post back in the code behind for the
ascx file, as it is common to various pages. I would, during this postback
period, like to access this processed data, and use it in the main page. How
do I access the data? Do I have to do anything special to ensure the .ascx
code is executed before the .aspx code, so that the information is ready?

Thanks,
Martin
 
J

Jared

Martin

How about moving your code to a class and populating public or session
variables with the data you require? You can then call your variables
from both the .ascx and .aspx.

I am not sure if you can force a .ascx to run first.

Cheers

Jared
 
J

Jared

You could try moving your code to a Class module and storing it as
Session or Public variables. You can then call these variables in both
the .ascx and .aspx.

I am not sure if you can ensure that the .ascx code runs first.

Jared
 
M

Martin Eyles

Martin said:
I have a .aspx page which has a .ascx file included through the lines

<%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %>
and
<aspcustom:menu id="Menu1" runat="server"></aspcustom:menu>

both of these files have vb.net code behind.

I am processing some information from a post back in the code behind for
the
ascx file, as it is common to various pages. I would, during this postback
period, like to access this processed data, and use it in the main page.
How
do I access the data? Do I have to do anything special to ensure the .ascx
code is executed before the .aspx code, so that the information is ready?

The problem with moving the information to a class is that the variable hang
over from another instance. I need the variable to be instance variables
rather than class variables, and I need to be able to access the same
instance from the .ascx file and .aspx file. My thought was that the code
behind the .aspx could reference the instance of Menu.ascx called Menu1, but
I get a blue underline in the code behind saying that Menu1 is not declared.

I thought there was a page lifecycle with init, load etc. I found a video
about it on MSDN TV, but It doesn't say what happens when there are .ascx
files involved as well as .aspx files. Does anyone have any ideas on this?

Thanks,
Martin
 
S

slagomite

Events for ASCX controls and their parent ASPX page do run in a
predefined manner with respect to the ASP.NET lifecycle. I never
remember the order in which events run for each -- so I usually just do
a Response.Write() inside each event handler for both the ASCX control
and the parent ASPX page, so I can quickly see which events run first.
Hopefully this will help.

Luke
 
M

Martin Eyles

Jared said:
You could try moving your code to a Class module and storing it as
Session or Public variables. You can then call these variables in both
the .ascx and .aspx.

I am not sure if you can ensure that the .ascx code runs first.

Thanks, I tried that - code appears to run in this order

..ascx init
..aspx load
..ascx load

so if I move some of my code in the .ascx file from the Page_Load to the
Page_Init, I can access the .ascx variables from the .aspx file's Page_Load
method.

Martin
 
M

Martin Eyles

Martin Eyles said:
Thanks, I tried that - code appears to run in this order

.ascx init
.aspx load
.ascx load

so if I move some of my code in the .ascx file from the Page_Load to the
Page_Init, I can access the .ascx variables from the .aspx file's
Page_Load method.

Martin

Sorry, replied to the wrong thread - this is in fact a reply to slagomite
suggestion - Ignore the text I quoted from Jared, and read the slagomite
text
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top