473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IsPostBack vs. OnClick

Is there considered a preferred method for handling the POST from an ASP.NET
web page? I'm a veteran with classic ASP, so have always used
Request.ServerVariables("REQUEST_METHOD") to check for POST. In choosing
between the new IsPostBack and the server side processing for the button
OnClick event, what criteria would be used to decide which method to use?
Or are they both equal, process-wise?
Nov 18 '05 #1
2 1419
Assuming the control that you're clicking has its AutoPostBack property set
to true, then when you click the control, you'll post back. When you post
back, whether by AutoPostBack, or by clicking some other control that causes
the form to be submitted, the process is the same. Page_Load runs first,
and then the event handlers for any pending events occur.

Theoretically, you could handle the entire postback in your Page_Load rather
than in your OnClick handler, but you should use the OnClick event for
processing code that is dependent on the click.

Dale

"Random" <ci*******@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP10.phx.gbl...
Is there considered a preferred method for handling the POST from an ASP.NET web page? I'm a veteran with classic ASP, so have always used
Request.ServerVariables("REQUEST_METHOD") to check for POST. In choosing
between the new IsPostBack and the server side processing for the button
OnClick event, what criteria would be used to decide which method to use?
Or are they both equal, process-wise?

Nov 18 '05 #2
"Random" <ci*******@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP10.phx.gbl...
Is there considered a preferred method for handling the POST from an ASP.NET web page?


Generally, one handles PostBack in the Page_Load handler:

private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Load your data from the database
DataBind();
}
else
{
// Do anything that still needs to be done on a postback, like
binding any controls with
// ViewState turned off
}
}
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3

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

Similar topics

2
by: patrick_a | last post by:
Hi, I'm having trouble with using !IsPostBack. I want to create a linkbutton within a table when the page loads the first time and then have the page redirect based on the...
5
by: nly | last post by:
Page.IsPostBack Property "The Page_Load subroutine runs EVERY time the page is loaded. If you want to execute the code in the Page_Load subroutine only the FIRST time the page is loaded, you can...
11
by: suzy | last post by:
hi, i have an aspx page with a button. if i step through my code when i click the button then it calls the button_Click event which is what i want. but i need to redirect the page to another...
3
by: Alan Pretre | last post by:
I have a a WebForms.Table control that I am populating in Page_Load(). One of the columns has cells with a button in each row, which I wire up to its Click event handler. Everything is fine if I...
2
by: Anand Sagar | last post by:
I have a Panel1 and button1 on my webform. At runtime, I create 2 textboxes. I do it at the Page_Load event. I put the code within the " If Not isPostBack" For the button click event, I will do...
4
by: TJ | last post by:
Hi, There is one aspx web page that contains usercontrol. In aspx page and usercontrol , there is each submit button... Here is what I want... I want to process something depending on each...
5
by: David Lozzi | last post by:
Hello, I have an interesting issue, so bear with me as I try to explain. I have a datalist posing as tabs for my application. And as each tab is clicked, a placeholder is then populated with the...
3
by: Guy Noir | last post by:
Hello again. I have a form that has 2 buttons. When button 1 is pressed, I want the form to execute a few tasks and give the user feedback. When button 2 is pressed, I want the form to reload as if...
5
by: BM | last post by:
I have a question that seems like it should have a simple answer, but I can't seem to find it by searching... Anyway, I'm trying to capture the IsPostBack event when I select an item within an...
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
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...
1
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.