473,753 Members | 6,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question re Event Firing Sequence

In diagnosing a problem, I noted that a button_click event gets run only
after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1, C#)

Can this be correct? I'm trying to set session variables in a Button_Click
event which determines how the page is supposed to appear in the PostBack,
so of course it fails.

Where should I put my code so that the session variables are re-set before
the PostBack?

Thanks

Phil
Mar 1 '06 #1
3 1315
This is correct.

You can't do anything BEFORE the postback, since it is the postback that
cause your application to run. You probably mean "in the beginning" of the
postback handling code. Just put it in the beginning of Page_Load event, if
you can. If you need to know what caused the postback, you can check
Request.Form["__EVENTTAR GET"] (works in most cases, but there are
exceptions), or pass it in your own hidden input.

Eliyahu

"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:OB******** ******@TK2MSFTN GP11.phx.gbl...
In diagnosing a problem, I noted that a button_click event gets run only
after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1,
C#)

Can this be correct? I'm trying to set session variables in a
Button_Click event which determines how the page is supposed to appear in
the PostBack, so of course it fails.

Where should I put my code so that the session variables are re-set
before the PostBack?

Thanks

Phil

Mar 2 '06 #2
Sorry, my post wasn't specific enough. I was trying to shorten a previous 2
page post and got overly terse.

I'm writing a user control which has two states: Active & InActive. I
additionally am required that there to be only one active control per page,
and all logic has to be contained within the control.
In its inactive state, only a single button appears. If the user clicks on
this button, the control becomes active( the rest of the control's
functionality becomes visible), and all other controls should become
inactive. When the user is finished with a control, they click the 'Done'
button, and the control becomes inactive.

I'm trying to do this by having a session variable for each control,
Session[ this.ControlID + "_ActiveSta te"] = { 0, 1 } and a single session
variable
Session[ "WhichControlIs Active "] = { 'None', "ControlID_ 1", "ControlID2 ",
.... , "ControlID_ N" }

When the user selects an inactive control, its Session[ this.ControlID +
"_ActiveSta te"] gets set to 1 in the Control.Activat eButton_Click(. .)
method, and Session[ "WhichControlIs Active" ] = this.ControlID; , and the
page gets posted back.

When the user is finished and clicks the 'Done' button, Session[
this.ControlID +"_ActiveSta te"] get set to 0, Session[
"WhichControlIs Acitve"] get set to 'None', and the page gets posted back.

I now want the new page to reflect the new session variables. My problem is
that the new session variables don't get saved until after the Page_Load
event of the new page, so these session variables are useless in structuring
the subsequent pages.

I can't use hidden fields, because they would have to be in a public place
( i.e. the containing page ), and I'm required to have all logic internal.
Similarly,
the Request.Form["_ "] isn't available to the controls.

Is there really no good way to do this?
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:ux******** ******@TK2MSFTN GP14.phx.gbl...
This is correct.

You can't do anything BEFORE the postback, since it is the postback that
cause your application to run. You probably mean "in the beginning" of the
postback handling code. Just put it in the beginning of Page_Load event,
if you can. If you need to know what caused the postback, you can check
Request.Form["__EVENTTAR GET"] (works in most cases, but there are
exceptions), or pass it in your own hidden input.

Eliyahu

"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:OB******** ******@TK2MSFTN GP11.phx.gbl...
In diagnosing a problem, I noted that a button_click event gets run only
after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1,
C#)

Can this be correct? I'm trying to set session variables in a
Button_Click event which determines how the page is supposed to appear in
the PostBack, so of course it fails.

Where should I put my code so that the session variables are re-set
before the PostBack?

Thanks

Phil


Mar 2 '06 #3
First, I think Request.Form["_ "] should be available for controls as long
as controls can get a pointer to the page they are on. Furthermore, the
UserControl class already has property Request.

Second, you don't need to access Request.Form["_ "] from the control in the
first place, just do it in the Page_Load event and you will now what control
initiated the postback.

Am I again missing something?

Eliyahu

"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Sorry, my post wasn't specific enough. I was trying to shorten a previous
2 page post and got overly terse.

I'm writing a user control which has two states: Active & InActive. I
additionally am required that there to be only one active control per
page, and all logic has to be contained within the control.
In its inactive state, only a single button appears. If the user clicks
on this button, the control becomes active( the rest of the control's
functionality becomes visible), and all other controls should become
inactive. When the user is finished with a control, they click the 'Done'
button, and the control becomes inactive.

I'm trying to do this by having a session variable for each control,
Session[ this.ControlID + "_ActiveSta te"] = { 0, 1 } and a single session
variable
Session[ "WhichControlIs Active "] = { 'None', "ControlID_ 1", "ControlID2 ",
... , "ControlID_ N" }

When the user selects an inactive control, its Session[ this.ControlID +
"_ActiveSta te"] gets set to 1 in the Control.Activat eButton_Click(. .)
method, and Session[ "WhichControlIs Active" ] = this.ControlID; , and the
page gets posted back.

When the user is finished and clicks the 'Done' button, Session[
this.ControlID +"_ActiveSta te"] get set to 0, Session[
"WhichControlIs Acitve"] get set to 'None', and the page gets posted back.

I now want the new page to reflect the new session variables. My problem
is that the new session variables don't get saved until after the
Page_Load event of the new page, so these session variables are useless in
structuring the subsequent pages.

I can't use hidden fields, because they would have to be in a public place
( i.e. the containing page ), and I'm required to have all logic internal.
Similarly,
the Request.Form["_ "] isn't available to the controls.

Is there really no good way to do this?
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:ux******** ******@TK2MSFTN GP14.phx.gbl...
This is correct.

You can't do anything BEFORE the postback, since it is the postback that
cause your application to run. You probably mean "in the beginning" of
the postback handling code. Just put it in the beginning of Page_Load
event, if you can. If you need to know what caused the postback, you can
check Request.Form["__EVENTTAR GET"] (works in most cases, but there are
exceptions), or pass it in your own hidden input.

Eliyahu

"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:OB******** ******@TK2MSFTN GP11.phx.gbl...
In diagnosing a problem, I noted that a button_click event gets run only
after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1,
C#)

Can this be correct? I'm trying to set session variables in a
Button_Click event which determines how the page is supposed to appear
in the PostBack, so of course it fails.

Where should I put my code so that the session variables are re-set
before the PostBack?

Thanks

Phil



Mar 5 '06 #4

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

Similar topics

13
7497
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
2
2904
by: Ben Fidge | last post by:
Hi I've got a TextBox on my WebForm with it's AutoPostback set to true, and an event handler created for the TextChanged event. I would expect this event to be fired when the user types any character into the textbox. However, the event is only firing when the users enters text and THEN moves to another control on the page.
0
435
by: ChrisB | last post by:
I'm attempting to open a new window from a LinkButton in a DataGrid. I can set a session variable in the ItemCommand event for the LinkButton like so: // this is used to handle the ItemCommand event private void itmCmd(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string itemGFNo = ""; if (e.CommandName == "EditTask")
8
1796
by: Paul | last post by:
Hi, In a class i built, i fire an event when a field changes. In a webform that has an instance of the class, the event (from the class) is fired and the code is executed. However, my webpage does not reload (postback) after the event fires. How do i get the webform to postback when the event fires (after the code in the event is done executing)? Thank you, Paul
3
1958
by: Guadala Harry | last post by:
Just wondering if I can count on Page_Load *always* firing before event procedures of other controls on the form. E.G., suppose I have a DropDownList server control and it is "autopostbacking". Will Page_Load always fire before the SelectedIndexChanged event of the DDL? Thanks.
2
2000
by: Dan | last post by:
I have an aspx page with a form on it. There are a couple of textboxes and an ImageButton. The page is loaded from another page using Server.Transfer. When I click on the ImageButton, the Page_Load event immediately fires on the codebehind page and then click event fires. When this happens, the Page.IsPostBack property is true in the page_load event. Why is the page_load event firing before the ImageButton_Click event?
4
9101
by: C M Shaw | last post by:
I have a form which I want to show modally; it's a fairly old form that's been ported up several versions of VB, and I'd like to keep its rewriting to a minimum. Basically, it is used in this sequence: 1. The form is shown. The Form_Load event does some initialization. 2. Further parameters are passed to this form. 3. We actually need this form to be modal, so we hide it and show it again modally. 4. Stuff happens on the form based...
8
1070
by: Bernie Yaeger | last post by:
I know I'm not getting this clearly: I set up a delegate to execute a method. I've done this with no problem re validating methods. For example: I set up the delegate like this: Delegate Sub callm_dropdown(ByVal sender As Object, ByVal e As System.EventArgs) Dim delegd As callm_dropdown Then I call it, say in a click event of a button:
2
3927
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever possible to make the app more efficient and less resource demanding. On one page there are 2...
0
9072
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9451
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8328
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6869
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
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.