473,405 Members | 2,334 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.

load order question

Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i set
a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload for
the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the variable
yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan
Nov 18 '05 #1
7 3439
Initialize your user control at Page Init (not page load).

Bill

"Dan Nash" wrote:
Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i set
a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload for
the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the variable
yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan

Nov 18 '05 #2
Dan,

I might try to move the code you have in the page load event for the page
into the PreRender event of the page. Therefore, executing after the page
load event for all controls and usercontrols.

HTH
-Chris

"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:BA**********************************@microsof t.com...
Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i set a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload for the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the variable yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan

Nov 18 '05 #3
Hi Dan,

Use the control's (or the page's) Init event.

The Page Init fires in the controls first then in the Page, then Page load
fires, then Load in the controls.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:BA**********************************@microsof t.com...
Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i set a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload for the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the variable yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan

Nov 18 '05 #4
Correct me if I wrong, not that I haven't used the Page Init event because I
have, but I hesitate to use in case I might need ViewState. ViewState gets
loaded somehwhere between the Page Init event and the Page Load event and
sometimes, I have had problems with not being able to access control
properties because that that fact.

That is why, I recommend using the PreRender event for the page since it
needs to access properties of the UserControl after the UserControl loads.

-Chris
~
http://weblogs.austinspad.com/caustin

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...
Hi Dan,

Use the control's (or the page's) Init event.

The Page Init fires in the controls first then in the Page, then Page load fires, then Load in the controls.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:BA**********************************@microsof t.com...
Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i

set
a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload

for
the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the

variable
yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan


Nov 18 '05 #5
Hi guys

I think I'm gonna try the PreRender event, basically because I'm not
declaring any controls at runtime, they've all been designed with the editor.

I know the PageLoad is firing before the control PageLoad, so logically
PreRender is the next event after that.

One question though.. am I ok "doing stuff" in the PreRender event? The
variable im getting from the control is an sql statement, so obviously once
ive got that, I need to be able to do my SQL connection stuff / databinding
etc.

Is this safe to do in PreRender?

Cheers
Dan

"Chris Austin" wrote:
Correct me if I wrong, not that I haven't used the Page Init event because I
have, but I hesitate to use in case I might need ViewState. ViewState gets
loaded somehwhere between the Page Init event and the Page Load event and
sometimes, I have had problems with not being able to access control
properties because that that fact.

That is why, I recommend using the PreRender event for the page since it
needs to access properties of the UserControl after the UserControl loads.

-Chris
~
http://weblogs.austinspad.com/caustin

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...
Hi Dan,

Use the control's (or the page's) Init event.

The Page Init fires in the controls first then in the Page, then Page

load
fires, then Load in the controls.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:BA**********************************@microsof t.com...
Hi guys

Ok, i have an aspx with a user control. In the user controls pageload i

set
a property (mystring = "test";). i then want to access that from the
page_load of the aspx thats using the control.

the problem is that the pageload for the page fires before the pageload

for
the control, so if i say in my pageload

response.write(control.mystring);

i get blank, because the controls pageload hasnt fired and set the

variable
yet.

how do i get round this problem?!!

much help appreciated.

cheers
dan



Nov 18 '05 #6
Dan, Prerender can be a great place to do "stuff." The big thing to remember
is that between Page Load and Page Prerender is where all the events (e.g.
button clicks) are processed, which may or may not be a good thing in your
case.

There's a great article by Peter van Ooijen here:
http://www.dotnetjunkies.com/Tutoria...9F4C739BC.dcik
From Mr. van Ooijen's article: "In a lot of example code a lot more happens
here [Page Load], like reading data from the database and binding the data to
the grid. I will not do that yet. The eventhandlers of the controls, like
button-clicks might update the data. It is a lot more efficient to wait to
the PreRender event. When that event is fired all handlers of button clicks
and the like have executed. The page is now ready to start writing the actual
response which will be sent to the user. It is the last opportunity to update
the components." His explanation of the order of events was a major light
bulb at least for me, so you might check it out.

I'd still suggest that if you're doing "initialization" type stuff in your
user control that it belongs in Init, but Chris is certainly right about
viewstate (the normal case is that you want to initialize your controls
*before* viewstate is restored).

It's hard to tell from your test example whether you should be doing
Init-->Load or Load-->Prerender, but don't be afraid of either, it's more
just understanding the implications of each.

hth,

Bill

"Dan Nash" wrote:
Hi guys

I think I'm gonna try the PreRender event, basically because I'm not
declaring any controls at runtime, they've all been designed with the editor.

I know the PageLoad is firing before the control PageLoad, so logically
PreRender is the next event after that.

One question though.. am I ok "doing stuff" in the PreRender event? The
variable im getting from the control is an sql statement, so obviously once
ive got that, I need to be able to do my SQL connection stuff / databinding
etc.

Is this safe to do in PreRender?

Cheers
Dan

"Chris Austin" wrote:
Correct me if I wrong, not that I haven't used the Page Init event because I
have, but I hesitate to use in case I might need ViewState. ViewState gets
loaded somehwhere between the Page Init event and the Page Load event and
sometimes, I have had problems with not being able to access control
properties because that that fact.

That is why, I recommend using the PreRender event for the page since it
needs to access properties of the UserControl after the UserControl loads.

-Chris
~
http://weblogs.austinspad.com/caustin

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...
Hi Dan,

Use the control's (or the page's) Init event.

The Page Init fires in the controls first then in the Page, then Page

load
fires, then Load in the controls.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Dan Nash" <da*@musoswire.co.uk> wrote in message
news:BA**********************************@microsof t.com...
> Hi guys
>
> Ok, i have an aspx with a user control. In the user controls pageload i
set
> a property (mystring = "test";). i then want to access that from the
> page_load of the aspx thats using the control.
>
> the problem is that the pageload for the page fires before the pageload
for
> the control, so if i say in my pageload
>
> response.write(control.mystring);
>
> i get blank, because the controls pageload hasnt fired and set the
variable
> yet.
>
> how do i get round this problem?!!
>
> much help appreciated.
>
> cheers
>
>
> dan


Nov 18 '05 #7
Cheers Bill - great article and a very useful post! I'm now not frightened to
put my "stuff" in PreRender :o)

"Bill Borg" wrote:
Dan, Prerender can be a great place to do "stuff." The big thing to remember
is that between Page Load and Page Prerender is where all the events (e.g.
button clicks) are processed, which may or may not be a good thing in your
case.

There's a great article by Peter van Ooijen here:
http://www.dotnetjunkies.com/Tutoria...9F4C739BC.dcik
From Mr. van Ooijen's article: "In a lot of example code a lot more happens
here [Page Load], like reading data from the database and binding the data to
the grid. I will not do that yet. The eventhandlers of the controls, like
button-clicks might update the data. It is a lot more efficient to wait to
the PreRender event. When that event is fired all handlers of button clicks
and the like have executed. The page is now ready to start writing the actual
response which will be sent to the user. It is the last opportunity to update
the components." His explanation of the order of events was a major light
bulb at least for me, so you might check it out.

I'd still suggest that if you're doing "initialization" type stuff in your
user control that it belongs in Init, but Chris is certainly right about
viewstate (the normal case is that you want to initialize your controls
*before* viewstate is restored).

It's hard to tell from your test example whether you should be doing
Init-->Load or Load-->Prerender, but don't be afraid of either, it's more
just understanding the implications of each.

hth,

Bill

"Dan Nash" wrote:
Hi guys

I think I'm gonna try the PreRender event, basically because I'm not
declaring any controls at runtime, they've all been designed with the editor.

I know the PageLoad is firing before the control PageLoad, so logically
PreRender is the next event after that.

One question though.. am I ok "doing stuff" in the PreRender event? The
variable im getting from the control is an sql statement, so obviously once
ive got that, I need to be able to do my SQL connection stuff / databinding
etc.

Is this safe to do in PreRender?

Cheers
Dan

"Chris Austin" wrote:
Correct me if I wrong, not that I haven't used the Page Init event because I
have, but I hesitate to use in case I might need ViewState. ViewState gets
loaded somehwhere between the Page Init event and the Page Load event and
sometimes, I have had problems with not being able to access control
properties because that that fact.

That is why, I recommend using the PreRender event for the page since it
needs to access properties of the UserControl after the UserControl loads.

-Chris
~
http://weblogs.austinspad.com/caustin

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...
> Hi Dan,
>
> Use the control's (or the page's) Init event.
>
> The Page Init fires in the controls first then in the Page, then Page
load
> fires, then Load in the controls.
>
> +++ Rick ---
>
> --
>
> Rick Strahl
> West Wind Technologies
> http://www.west-wind.com/
> http://www.west-wind.com/weblog/
> http://www.west-wind.com/wwThreads/
> ----------------------------------
> Making waves on the Web
>
>
> "Dan Nash" <da*@musoswire.co.uk> wrote in message
> news:BA**********************************@microsof t.com...
> > Hi guys
> >
> > Ok, i have an aspx with a user control. In the user controls pageload i
> set
> > a property (mystring = "test";). i then want to access that from the
> > page_load of the aspx thats using the control.
> >
> > the problem is that the pageload for the page fires before the pageload
> for
> > the control, so if i say in my pageload
> >
> > response.write(control.mystring);
> >
> > i get blank, because the controls pageload hasnt fired and set the
> variable
> > yet.
> >
> > how do i get round this problem?!!
> >
> > much help appreciated.
> >
> > cheers
> >
> >
> > dan
>
>

Nov 18 '05 #8

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

Similar topics

1
by: CST | last post by:
Hi All, I have a "Digital Dashboard" that basically has 4 IFrame sections. The page flows in the following order: Messages, Stocks, Weather, User Links. Please note that this order needs to...
1
by: Ken | last post by:
Is there any way that a literal can be used for a field value in the load statement? The context is fixed-length record formats, db2 8.1 ese, aix 5.1. I'm performing warehouse and mart loads...
1
by: John Hunter | last post by:
I've recently had a nasty problem with the "Invalid reference to the property Form" error in subforms - nasty because it doesn't seem to consistently happen to all forms which contain the same...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
2
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the...
4
by: www.MessageMazes.com | last post by:
Greetings, I'm working on a collection of free puzzle pages that serve as a feed to sale pages. My question is whether I can specify that some images load before others? If you visit...
10
by: aj | last post by:
DB2 WSUE LUW v8.2 FP4 (aka v8.1 FP11) RHEL AS 4 I am EXPORTing in IXF format from one schema and then LOADing into another schema on another server. The DB modeling tool I am using likes to...
0
by: shaqa | last post by:
I try to do this but i cannot. i creat two layers with actionscript seperated as slideshow need to be,,and i try to put in one rectangle all of my images but cannot put in work,it doesnt load when i...
2
by: millevlada | last post by:
Hi all. Here is description of my run-time assembly loading problem: I would like to have winService hosting .Net remoting objects. But, it should work in sort of pluginable way, so during...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.