473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

accessing .ascx data from .aspx

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
Jan 17 '06 #1
6 2592
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

Jan 17 '06 #2
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

Jan 17 '06 #3
Martin Wrote:
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" <ja***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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.
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
Jan 17 '06 #4
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

Jan 17 '06 #5

"Jared" <ja***********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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
Jan 19 '06 #6

"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com...

"Jared" <ja***********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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
Jan 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
2
by: Brenden Bixler | last post by:
I have a user control, dropdown.ascx Inside dropdown.ascx, I have a dropdownlist control. From my page.aspx, I need to be able to access the dropdown's value. By setting it to auto-post...
7
by: hummh | last post by:
Hello out there, I´m making my first steps with ASP.NET 2.0 and have he following problem: I´ve implemented a Web User Control that sits in the root of my ASP.NET Website. I want to use the...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
0
by: schneider | last post by:
Hi all, I created a User Control "SlideShow.ascx" in my application's root. Then I created a subfolder and an aspx page "MySlideShow1.aspx" in there. I added an instance of the ascx control to...
5
by: michael234 | last post by:
Hi All, Before i get into things I'm writing in C# using VS2003 with framework 1.1. I am having a problem accessing a user control in the code behind. I'm using the user control for some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.