Board index » Web Programming » accessing .ascx data from .aspx

accessing .ascx data from .aspx

Web Programming238
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


-
 

Re:accessing .ascx data from .aspx

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



-

Re:accessing .ascx data from .aspx

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



-

Re:accessing .ascx data from .aspx

Martin Wrote:

Quote
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?



"Jared" <jaredfholgate@gmail.com>wrote in message

news:1137501736.285560.160800@g47g2000cwa.googlegroups.com...

>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.



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.



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



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





-

Re:accessing .ascx data from .aspx

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



-

Re:accessing .ascx data from .aspx



"Jared" <jaredfholgate@gmail.com>wrote in message

Quote
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





-

Re:accessing .ascx data from .aspx



"Martin Eyles" <martin.eyles@NOSPAMbytronic.com>wrote in message

Quote


"Jared" <jaredfholgate@gmail.com>wrote in message

news:1137500698.323193.275620@g44g2000cwa.googlegroups.com...

>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



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





-