473,386 Members | 1,823 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,386 software developers and data experts.

A Question about Events

DC
In a book sample I am working through in ASP.NET, a simple Hello World works
fine, but the order of events has me confused.

The sample involves a Button control and the onClick event. On click, the
page reloads and voila, hello world is written (I understand this part).

However, when I set a breakpoint on both Page_Load and onClick, Page_Load is
accessed first, stepping through takes me to onClick.

But "Hello World" is written outside of all HTML elements. I was under the
impression that on Page_Load the HTTP stream is persisted until processing
of events is completed, so why isnt Hello World written in the HTML elements
(specifically, the BODY tag)?

Thank you!
Nov 18 '05 #1
1 930
The HTML tags are processed after the load. I am not sure which book you are
working with, but it is a bad ASP.NET example (many are). As ASP.NET works
on a binding model, you are best to place a container (a panel comes to
mind) on the page and add controls (for plain text, use a LiteralControl).

Page_Load runs every time the page loads. So, it is natural it will run
every time. It is not a great event to slap in a bunch of stuff; use the
button event instead. The normal signature should be something like:

protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostback)
{
//Something that runs on a hit without a postback
}
else
{
//Code that runs EVERY time a page is posted back to
//NOTE: Do not make a conditional tree here,
// use the postback events instead
}
}

In most books, you see the horrible code tree like:

if(!Page.IsPostback)
//set up initial page
else
if condition1
// lots of code here
else if condition 2
//lots of code here
else
//lots of code here

protected void btnWhatever_Click(object sender, EventArgs e)
{
//empty routine
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"DC" <dc@blah.com> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
In a book sample I am working through in ASP.NET, a simple Hello World works fine, but the order of events has me confused.

The sample involves a Button control and the onClick event. On click, the
page reloads and voila, hello world is written (I understand this part).

However, when I set a breakpoint on both Page_Load and onClick, Page_Load is accessed first, stepping through takes me to onClick.

But "Hello World" is written outside of all HTML elements. I was under the
impression that on Page_Load the HTTP stream is persisted until processing
of events is completed, so why isnt Hello World written in the HTML elements (specifically, the BODY tag)?

Thank you!

Nov 18 '05 #2

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: Steve | last post by:
I've run in to a problem with a query I'm trying to write. I have attached a sample SQL script at the end of this post to show an overview of what I'm working with. I want to be able to use...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
4
by: news.microsoft.com | last post by:
In one of my books called "Mastering C#" there is a statement that reads "All event handler delegates must return void and accept two parameters. The first parameter is an object, and it represents...
1
by: Christoph Boget | last post by:
Where can I find *comprehensive* information about events? I've been all through Microsofts developer pages, through the VS.NET help but I can't find comprehensive, details information about them....
6
by: Flare | last post by:
Hi i have a qusstion about events and delegates. Especially the precis role of the Event. Eg. We have a class wich want to fire events so we declare: public delegate void...
1
by: e-mid | last post by:
i registered two events with a button. when i press it , how can i know which is fired first? or is there a way to make one of them get fired before the other one? in fact i made a experiment...
1
by: Tom Rahav | last post by:
Hi, I use VB .NET 2003 and I want to create a new UserControl that will function as a "smart" combobox that handles few events automatically (such as auto-complete, etc.) in addition to the...
8
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...

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.