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

how do I know it's posted back due to a button click in Form_Load

Hello,
I have an asp button control(called buttonA), and in the Form_Load event I
want to know if the postback is due to the click of ButtonA. Which method
should I use to achieve this?

Thanks,
Jazz
Apr 27 '06 #1
5 1335
Probably a better way but right off the top here goes.

asp:hiddenfield, session key, querystring, etc...

protected void _buttonA_Click(object sender, EventArgs e)
{
_hiddenField.Value = "A";
// you could also do the following:
// Session["sessionKey"] = "A";
}
if(_hiddenField == "A")
{
// do something here
}

if(Session["sessionKey"].ToString() == "A")
{
// do something here
}

Apr 27 '06 #2
Paul,
What I want is to detect if it's from ButtonA click in the Form_Load
even(this is before the ButtonCLick event gets called), and if it is I will
skip some code in the Form_Load .

Thanks,
Jazz
Apr 27 '06 #3
What do you mean by the Form_Load event, do you have a control called Form
and Form_Load is the event handler for it's OnLoad event?

"Jazz" wrote:
Paul,
What I want is to detect if it's from ButtonA click in the Form_Load
even(this is before the ButtonCLick event gets called), and if it is I will
skip some code in the Form_Load .

Thanks,
Jazz

Apr 28 '06 #4
Jazz wrote:
Paul,
What I want is to detect if it's from ButtonA click in the Form_Load
even(this is before the ButtonCLick event gets called), and if it is I will
skip some code in the Form_Load .

Thanks,
Jazz


In VB:

If Not Request.Params("ButtonA") is Nothing Then
'Do stuff if button A was pressed
Else
'Do stuff if button A wasn't pressed
End If

However, I wouldn't recommend it. You've now, potentially, got two
places where code reacts to button presses - in the Page Load event and
in the button Click event. A future maintainer (or a future you) may be
confused if they don't spot the code in Page Load, and spend valuable
time trying to diagnose why the page acts differently when the button
is pressed.

Perhaps if you could elaborate on what behaviour you're altering, we
could suggest some viable alternatives?

Damien

Apr 28 '06 #5

In the Form Load event handler, can't you interrogate the sender object
to determine whether or not button A was pressed?

Bill
*** Sent via Developersdex http://www.developersdex.com ***
Apr 28 '06 #6

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

Similar topics

4
by: John | last post by:
Could anyone please help me on this?? I have a php script page, which is basically quiz. Visitors (after login in with their email address) are supposed to answer each question, and when they...
21
by: Dan V. | last post by:
I have tried a number of things including preloading, but the background image (water tile in header) in IE 6 will not display where other browsers will....
1
by: Susan Bricker | last post by:
Greetings. I am trying to position opened forms so that they are cascaded on the screen. I have discovered the movesize action (for the DoCmd) and Move property of a form (for Acc 2002/2003). ...
1
by: Ireney Berezniak | last post by:
Hey guys, I have a problem with events misfiring when the back button is used. I have two controls (a drop-down list and a text field) and two buttons, one for each of the controls, on a...
1
by: dhurwitz | last post by:
Hi I have developed a web app with a dozen or so pages, which allows searching for and editing orders by OrderID. There is a search page for entering multiple search criteria. In addition, each...
3
by: Lloyd Sheen | last post by:
I have several apps that use a roll your own approach, but I am embarking on a project which will not allow that with the time constraints. I have gened up a little app to try the databinding...
2
by: Tom wilson | last post by:
This is a huge problem. I'm going insane. I've tried to solve this elsewhere and no one can suggest how to make this work. To me, this should be a very basic thing to do. I have an asp.net...
7
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly...
3
by: panget | last post by:
I am supposed to create a form with a flexgrid that should display all contents of my database books.mdb. I also added a button called "Add" which when clicked should display another form with...
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
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...
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
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...

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.