Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how do I know it's posted back due to a button click in Form_Load

Reply
Thread Tools

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

 
 
=?Utf-8?B?SmF6eg==?=
Guest
Posts: n/a
 
      04-27-2006
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
 
Reply With Quote
 
 
 
 
Paul Bush
Guest
Posts: n/a
 
      04-27-2006
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
}

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmF6eg==?=
Guest
Posts: n/a
 
      04-27-2006
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
 
Reply With Quote
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      04-28-2006
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

 
Reply With Quote
 
Damien
Guest
Posts: n/a
 
      04-28-2006
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

 
Reply With Quote
 
Bill Gregg
Guest
Posts: n/a
 
      04-28-2006

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 ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM
Button causes Form_Load to fire, before Button_Click Paul Aspinall ASP .Net 1 08-12-2003 07:12 PM
Button causes Form_Load to fire, before Button_Click Paul Aspinall ASP .Net Web Controls 0 08-12-2003 05:08 PM



Advertisments