Determine Which Button Pressed

G

Guest

In my page initialize, I am loading dynamic controls for a survey. On the
survey, I have a stop button. If the user clicks the stop button, because of
the page life cycle, the initialize and page load events run before the
button click and reloads a bunch of controls. Is there a way to keep these
events from running with a button control. The click event of the button has
code to save the user's place in the survey and I only want it to run. Thanks.
 
J

Juan T. Llibre

re:
I am only using ASP.Net 1.0. As far as I know, there is no wizard for that.

What the h*ll are you doing using ASP.NET 1.0 ?

At the very least you should be using ASP.NET 1.1.
although everybody should be, at least, testing ASP.NET 2.0.
 
J

Juan T. Llibre

re:
That was a typo. Is this better: v1.1.4322.

Yes, that's better.

re:
I would like help instead of criticism.

Posting correct information would help you in getting help.

You should consider upgrading to 2.0.
Is there anything stopping you from doing that ?
 
G

Guest

Thanks...I realize correct information is much better when needing help.
Sorry for the typo.

The office where I work just started using VS 2003 this year, so there are
no plans to upgrade for at least 2 years.
 
J

Juan T. Llibre

re:
Thanks...I realize correct information is much better when needing help.
Sorry for the typo.

No problem...

re:
The office where I work just started using VS 2003 this year,
so there are no plans to upgrade for at least 2 years.

Do the guys who run your office realize that VWD is free ?
Also, do they realize that running the .Net Framework 2.0 is free ?

They're free downloads.

Get VWD at :
http://msdn.microsoft.com/vstudio/express/vwd/download/

You can also download the free .Net Framework 2.0 redistributable at :
http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-436...

And, you can download, for free, the .Net Framework 2.0 SDK at :
http://www.microsoft.com/downloads/details.aspx?familyid=FE6F2099-B7B...

With VWD and the .Net Framework redistributable -or the SDK- there's no need
to spend money for an IDE which *can* target .Net Framework 2.0 objects.

You can continue to use VS 2003 for your .Net Framework/ASP.NET 1.1 development.
That won't interfere with your *free* development of ASP.NET 2.0 apps.
 
G

Guest

I did not realize that VS 2003 could take advantage of the new things in the
2.0 framework, but we have a very rigid process that keeps us from being to
upgrade until approved by higher until they have "fully" tested it. The one
great day I am on my own, I'll work with all the latest and greatest :)

Do you know if I can do what I need in VS 2003?
 
M

Mark Rae

In my page initialize, I am loading dynamic controls for a survey. On the
survey, I have a stop button. If the user clicks the stop button, because
of
the page life cycle, the initialize and page load events run before the
button click and reloads a bunch of controls. Is there a way to keep these
events from running with a button control. The click event of the button
has
code to save the user's place in the survey and I only want it to run.
Thanks.

You've obviously tried if (!Page.IsPostback) ...?
 
M

Mark Rae

I did not realize that VS 2003 could take advantage of the new things in
the
2.0 framework,

It can't, but that's not what Juan actually said...
but we have a very rigid process that keeps us from being to
upgrade until approved by higher until they have "fully" tested it. The
one
great day I am on my own, I'll work with all the latest and greatest :)

Maybe that time has come...
Do you know if I can do what I need in VS 2003?

private void Page_Init(object sender, EventArgs e)
{
// create your dynamic buttons - you'll need to do this every time the
page loads irrespective of whether it's been posted back or not

if (!Page.IsPostback)
{
// do something which won't happen when the page is posted back
}
}

private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostback)
{
// do something which won't happen when the page is posted back
}
}
 
G

Guest

This is what I have right now in the initialize event:

private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();

if (Page.IsPostBack)
{
//Load dynamic controls.
LoadNextSurveyPage();
}

base.OnInit(e);
}

I am doing Page.IsPostBack so it does not run on the initial load because we
are displaying instructions first., so I am wondering how to use the "stop
survey" button that I added through the designer to keep the above from
running.
 
K

Kevin Jones

You can't stop the events from firing but you might be able to use some
heuristics to determine which button caused the postback.

In your Page_xxx handlers you can look at the post body and check to see
if the btn data is in there. For example, if I have this

<asp:Button runat="server" id="stop" Text="Stop Survey"/>

Then in the event handler the Request object's items collection will
have a key called "stop" with the value "Stop Survey" so you could look
for that combination in the handlers alongside the IsPostback flag and
use that information to not use the postback.

If this is too kludgy then you could use a hidden form field, then when
the user clicks on the stop button use a javascript function to set the
value of the control before sending the postback to the server. You
could then use the items collection to look for that value,

Kevin
 
G

Guest

I added this to the initialize event and it worked...thanks.

if ((Page.IsPostBack) && (Request.Params.Get("btnStop") == null))
{
...code to load dynamic controls
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top