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

Page_Load vs Button_Click

Hi;

The examples I have seen all use "if (IsPostBack) { ... }" to handle an
action when the user presses the submit button.

However, it seems to me a more object oriented approach is to use a callback
event attached to a button.

Is there a good reason to use one over the other?

--
thanks - dave
Nov 19 '05 #1
2 1445
Actually, most of the time you'll see both. The IsPostBack is usually
checked for in the Page_Load event to avoid unnecessary calls to the db, for
example to populate a datalist when you don't need it populated because of
the actions your about to do with the button. You are correct, it's best to
handle as much as you can with a button handler because it provides the
greatest flexibility. Checking for a button firing in the Page_Load works
nicely, but only if you're going to have one button, adding a second will
just mess things up unless your approach is taken and good object-oriented
design is used.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"David Thielen" <th*****@nospam.nospam> wrote in message
news:13**********************************@microsof t.com...
Hi;

The examples I have seen all use "if (IsPostBack) { ... }" to handle an
action when the user presses the submit button.

However, it seems to me a more object oriented approach is to use a
callback
event attached to a button.

Is there a good reason to use one over the other?

--
thanks - dave

Nov 19 '05 #2
David Thielen wrote:
Hi;

The examples I have seen all use "if (IsPostBack) { ... }" to handle an action when the user presses the submit button.

However, it seems to me a more object oriented approach is to use a callback event attached to a button.

Is there a good reason to use one over the other?


When there are too many events, your Page_Load (or OnLoad) becomes very
big. It's better to use ASP.NET's event handling mechanism and
Page_Load should be used for page-related initialization only.

Nov 19 '05 #3

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

Similar topics

0
by: in | last post by:
I pass a variable from one aspx page to another using Context.Item.Add This works fine when the page first loads. I set the value of a static global var to the value of Context.Item in the...
2
by: C K | last post by:
I am having trouble getting the page_load event to fire from within my usercontrol - my code is below, I'm sure I'm missing something simple. Just your basic web user control - I've just began...
7
by: A.M | last post by:
Hi, I want to refresh my DataGrid data on every postback. I have following code in Page_Load event, but after first page load, the DataGrid never gets refresh. Here is the code i have in...
7
by: Jibey | last post by:
Hello: I'm facing a very strange problem. When I run my Web application in Visual Studio.NET the Page_Load event is not executing. Other events like a Button_Click are executing. It doesn't...
2
by: Skating_vince | last post by:
I have a problem, i have a form with some input boxes and a submit button. In the Submit_Click event, the data from the input boxes is stored in a database. But, if you click the button, ASP.NET...
2
by: Krista Lemieux | last post by:
Hello, In my form I have a button, and the button_Click function (which gets called when the button is clicked). However the functionality that I have in the button_Click function, needs to be...
2
by: Frank Schumacher | last post by:
Hi Folks, I have a problem with the order of events fired by ASP.NET. I found many articles which explaining the lifecycle of a site, but I found none which took the event from a Control on the...
0
by: Leszek Taratuta | last post by:
Hello, I load a user control using Page.LoadControl(). The user control contains two web controls: a drop-down list and a text box. The problem is that the SelectedItem as well as Text...
17
by: Arpan | last post by:
When a Button is clicked in a Web Form in an ASPX page, the Form will post back to itself. Under such circumstances (i.e. when a Button is clicked), will the Page_Load sub execute first & then will...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.