Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2007, 08:15 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The only thing I am hung up on is why you need to have 2 Page_Load events.

Wouldnt it be just as easy to do:

protected void Page_Load(object sender, EventArgs e)
{
  if(!Page.IsPostBack)
  {
     doLoginStuff();
     doFeaturedProducts();
  }
}

I don't know. I am glad you got your issue resolved though.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 6th, 2007, 02:41 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I was just talking to a guy in the HTML forum with a similar problem. I was under the impression that in ASP.NET you only need one handler.

Then no matter how much you need to do on page load, you keep writing code for all you need to do inside the event handler until it does all the actions you need to do.

So you have one handler, but all the different actions it needs to take are collected inside (hence the more urgent need for clean coding). Is this wrong?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old September 6th, 2007, 02:48 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You only need one handler (I am assuming you are refering to Page_Load) but, as Imar demonstrated, you can have as many as you want.

Depending on the Programmer, the Page_Load event may only ever execute an Action one time (like binding a control to a datasource for example) and all subsequent post backs could be handled by different control events.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 6th, 2007, 03:05 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Yes, I was referring to Page_Load, though I assume (always dangerous) that the principle extends to any event handler.

And just to clarify, you CAN use different post backs, but those are functionality related issues for your application. You don't NEED to do it just to effect multiple actions, you can run multiple actions inside one event handler (Page_Load or anything else).

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old September 6th, 2007, 03:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:So you have one handler, but all the different actions it needs to take are collected inside (hence the more urgent need for clean coding). Is this wrong?
Not al all....

As Doug suggested, you can have something like:

doLoginStuff();
doFeaturedProducts();

in your Page_load. You can call as many other methods as you see fit. The good thing about using separate methods is that you can reuse them from other events as well. E.g. when !Page.IsPostBack you call GetData() and from some event triggered by some data bound control you can call the same method again.....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
simple report and crystal report in vb.net saket123 .NET Framework 2.0 0 August 13th, 2008 06:55 AM
Indian Rs Format simple Function for vb.net s.karthik General .NET 0 March 24th, 2008 06:27 AM
MSSQL 2005 and MSSQL 2000 tiredcat Visual Basic 2005 Basics 0 April 9th, 2007 12:56 AM
Simple ASP.NET message box with VB janicen General .NET 1 February 24th, 2005 03:31 AM
VB MSSQL database REmote connectivity srichary Pro VB Databases 0 November 28th, 2004 06:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.