473,320 Members | 2,147 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,320 software developers and data experts.

Confused about writing Page Events in C# ASP.NET

So by default the editor only throws in "protected void Page_Load"
event.
What is the correct way to add in other events.

I had in the past copied the events from other pages where I had
manually typed them in such as:

protected void Page_LoadComplete(object sender, EventArgs e)
{

}

So recently I started to skip this ... thinking there was an easier
way... and I started wiring these up in the Page_Load event. Example:

protected void Page_Load(object sender, EventArgs e)
{
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
}

This is great because it throws in all the scaffold-like code that I
need.
But I just noticed today that this causes my Page.LoadComplete method
to be run twice!

What is the proper way to do this stuff in C# ASP.NET 2.0? I know
VB.NET has the nice dropdown at the top that helps you declare the
Page events. What is the right way to do this in C#?

Thanks,
Kelly Greer
ke*********@nospam.com
change nospam to yahoo
Feb 6 '08 #1
2 5127
Other than that, you may want to add a IsPostBack control before hooking
the event in Page Load:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
}
It seems like the "Page_LoadComplete executing twice" problem would stem
from having AutoEventWireup set to true and then wiring up the event in page
load too, not from IsPostBack.

Feb 6 '08 #2
Sorry two follow up questions:
Why does "Page_Load" or "Page_LoadComplete" even work without the
wiring (explicitly setting the EventHandler)?
Search help for AutoEventWireup. You will probably find
"AutoEventWireup=true" in your @Page declaration in the .aspx page. You can
set it to "false" to disable the behavior.
How many of these things are "AutoMagically" triggered by the ASP.NET
engine?
I believe that it is only Page events.

Feb 6 '08 #3

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

Similar topics

4
by: George Stout | last post by:
First off I do not know alot about writing queries to an Access Database from an ASP page. This is why I need help. I have an Events database for 6 colleges in our metro area. On the homepage I...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
3
by: C CORDON | last post by:
I am verry confused about classes. I understand that classes can encapsulate properties, methods, events (don't know hoy to add events to a class), etc. I am confused with this: if you can...
3
by: Michael Tissington | last post by:
I'm confused by documentation and examples on using Delegate to create Events for use with COM In some situation I see a parameter list of (sender as Object, e as EventArgs) and other times I...
1
by: tim | last post by:
Someone using Python Midi Package from http://www.mxm.dk/products/public/ lately? I want to do the following : write some note events in a midi file then after doing that, put some controllers...
7
by: AndrewMBaldwin | last post by:
I have a grid control (inherits from Placeholder) that has a few buttons on it. On this grid there is a filter form, which allows the user to filter/search the table for specific information. My...
5
by: Carlo Marchesoni | last post by:
I read that autoeventwireup="false" doesn't cause Page_Load to fire automatically and trying it out with a simple page this can be confirmed easily. However, I have a page with...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.