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

Page_Load call during POSTBACK

Hello,
This has probably been asked several times, but It must be clarified for me.

I would like to know why sometimes during a postback Page_Load is called
after the function marked for postback.
Here's the deal : From now on, I set CurrentThread.CurrentCulture only
during PageLoad. so date and currency format is incorrect if page load is
not called first.
What should I do to ensure that CurrentThread.CurrentCulture is alway set
correctly as soon as a postback is hit.
TIA.
Nov 19 '05 #1
6 2376
Olivier:
First off, I would probably put code like that int he
Application_BeginRequest of the Global.asax or an http module. This will
ensure that it's set up before any page events fire.

As for the page_load situation, it SHOULD always fire BEFORE the postback
handler. If it doesn't, there's something very wrong. Is it consistent for
a given page? Perhaps some code would help solve the problem...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
Hello,
This has probably been asked several times, but It must be clarified for
me.

I would like to know why sometimes during a postback Page_Load is called
after the function marked for postback.
Here's the deal : From now on, I set CurrentThread.CurrentCulture only
during PageLoad. so date and currency format is incorrect if page load is
not called first.
What should I do to ensure that CurrentThread.CurrentCulture is alway set
correctly as soon as a postback is hit.
TIA.

Nov 19 '05 #2
I'm able to reproduce the problem for the postback handler.
To be more specific, a combobox inside a datagrid Item (Footer or EditItem)
is marked to autopostback on event "OnSelectedIndexChanged" :

From ASPX file :
.......
<FooterTemplate>
<asp:DropDownList id=lstColumnId_New AutoPostBack="True" Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_New"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:Label id=lblColumnID_Original runat="server" Visible="False"
text='<%#DataBinder.Eval(Container.DataItem, "ColumnId")%>'>
</asp:Label>
<asp:DropDownList id=lstColumnId_Updated AutoPostBack="True" Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_Updated"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</EditItemTemplate>
.......

Below is code taken from InitializeComponent about the Datagrid :
this.grdFilterDetails.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemCreated);

this.grdFilterDetails.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_ItemCommand);

this.grdFilterDetails.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_CancelCommand);

this.grdFilterDetails.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_EditCommand);

this.grdFilterDetails.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_UpdateCommand);

this.grdFilterDetails.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemDataBound);
Here is the call stack when the postback function is called :
rtefaxqueues.dll!RTEFaxQUEUES.Filters.FilterOperan dFromlstColumnId_New(System.Object
sender = {System.Web.UI.WebControls.DropDownList}, System.EventArgs e =
{System.EventArgs}) Line 671 C# [<Non-user Code>]

Note that ItemCreated event is called before the one above.

TIA.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Olivier:
First off, I would probably put code like that int he
Application_BeginRequest of the Global.asax or an http module. This will
ensure that it's set up before any page events fire.

As for the page_load situation, it SHOULD always fire BEFORE the postback
handler. If it doesn't, there's something very wrong. Is it consistent
for a given page? Perhaps some code would help solve the problem...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
Hello,
This has probably been asked several times, but It must be clarified for
me.

I would like to know why sometimes during a postback Page_Load is called
after the function marked for postback.
Here's the deal : From now on, I set CurrentThread.CurrentCulture only
during PageLoad. so date and currency format is incorrect if page load is
not called first.
What should I do to ensure that CurrentThread.CurrentCulture is alway set
correctly as soon as a postback is hit.
TIA.


Nov 19 '05 #3
First, have you tried the Application_beginRequest idea?

I'm a little confused by the 2nd part. You say that ItemCreated is called
before FilterOperandFromlstColumnId_Updated, which is what should be
happening. Page_Load is called before ItemCreated... seems like everything
works according to plan..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
I'm able to reproduce the problem for the postback handler.
To be more specific, a combobox inside a datagrid Item (Footer or
EditItem) is marked to autopostback on event "OnSelectedIndexChanged" :

From ASPX file :
......
<FooterTemplate>
<asp:DropDownList id=lstColumnId_New AutoPostBack="True" Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_New"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:Label id=lblColumnID_Original runat="server" Visible="False"
text='<%#DataBinder.Eval(Container.DataItem, "ColumnId")%>'>
</asp:Label>
<asp:DropDownList id=lstColumnId_Updated AutoPostBack="True"
Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_Updated"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</EditItemTemplate>
......

Below is code taken from InitializeComponent about the Datagrid :
this.grdFilterDetails.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemCreated);

this.grdFilterDetails.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_ItemCommand);

this.grdFilterDetails.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_CancelCommand);

this.grdFilterDetails.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_EditCommand);

this.grdFilterDetails.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_UpdateCommand);

this.grdFilterDetails.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemDataBound);
Here is the call stack when the postback function is called :
rtefaxqueues.dll!RTEFaxQUEUES.Filters.FilterOperan dFromlstColumnId_New(System.Object
sender = {System.Web.UI.WebControls.DropDownList}, System.EventArgs e =
{System.EventArgs}) Line 671 C#

[<Non-user Code>]

Note that ItemCreated event is called before the one above.

TIA.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Olivier:
First off, I would probably put code like that int he
Application_BeginRequest of the Global.asax or an http module. This will
ensure that it's set up before any page events fire.

As for the page_load situation, it SHOULD always fire BEFORE the postback
handler. If it doesn't, there's something very wrong. Is it consistent
for a given page? Perhaps some code would help solve the problem...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
Hello,
This has probably been asked several times, but It must be clarified for
me.

I would like to know why sometimes during a postback Page_Load is called
after the function marked for postback.
Here's the deal : From now on, I set CurrentThread.CurrentCulture only
during PageLoad. so date and currency format is incorrect if page load
is not called first.
What should I do to ensure that CurrentThread.CurrentCulture is alway
set correctly as soon as a postback is hit.
TIA.



Nov 19 '05 #4
I'v not tried Application_BeginRequest yet.

Call order seen by writing to a log file function name :

1) ItemCreated
2) FilterOperandFromlstColumnId_New
3) Page_Load.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
First, have you tried the Application_beginRequest idea?

I'm a little confused by the 2nd part. You say that ItemCreated is called
before FilterOperandFromlstColumnId_Updated, which is what should be
happening. Page_Load is called before ItemCreated... seems like everything
works according to plan..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
I'm able to reproduce the problem for the postback handler.
To be more specific, a combobox inside a datagrid Item (Footer or
EditItem) is marked to autopostback on event "OnSelectedIndexChanged" :

From ASPX file :
......
<FooterTemplate>
<asp:DropDownList id=lstColumnId_New AutoPostBack="True" Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_New"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:Label id=lblColumnID_Original runat="server" Visible="False"
text='<%#DataBinder.Eval(Container.DataItem, "ColumnId")%>'>
</asp:Label>
<asp:DropDownList id=lstColumnId_Updated AutoPostBack="True"
Runat="server"
OnSelectedIndexChanged="FilterOperandFromlstColumn Id_Updated"
DataValueField="ColumnId" DataTextField="ColumnName" DataSource="<%#
GetColumns() %>">
</asp:DropDownList>
</EditItemTemplate>
......

Below is code taken from InitializeComponent about the Datagrid :
this.grdFilterDetails.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemCreated);

this.grdFilterDetails.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_ItemCommand);

this.grdFilterDetails.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_CancelCommand);

this.grdFilterDetails.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_EditCommand);

this.grdFilterDetails.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.grdFilterDetails_UpdateCommand);

this.grdFilterDetails.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.grdFilterDetails_ItemDataBound);
Here is the call stack when the postback function is called :
rtefaxqueues.dll!RTEFaxQUEUES.Filters.FilterOperan dFromlstColumnId_New(System.Object
sender = {System.Web.UI.WebControls.DropDownList}, System.EventArgs e =
{System.EventArgs}) Line 671 C#

[<Non-user Code>]

Note that ItemCreated event is called before the one above.

TIA.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Olivier:
First off, I would probably put code like that int he
Application_BeginRequest of the Global.asax or an http module. This
will ensure that it's set up before any page events fire.

As for the page_load situation, it SHOULD always fire BEFORE the
postback handler. If it doesn't, there's something very wrong. Is it
consistent for a given page? Perhaps some code would help solve the
problem...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Olivier Matrot" <ol****************@online.nospam> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
Hello,
This has probably been asked several times, but It must be clarified
for me.

I would like to know why sometimes during a postback Page_Load is
called after the function marked for postback.
Here's the deal : From now on, I set CurrentThread.CurrentCulture only
during PageLoad. so date and currency format is incorrect if page load
is not called first.
What should I do to ensure that CurrentThread.CurrentCulture is alway
set correctly as soon as a postback is hit.
TIA.



Nov 19 '05 #5
Hi Oliver,

Based on the code sinppet and event sequence you pasted,

1) ItemCreated
2) FilterOperandFromlstColumnId_New
3) Page_Load.

the 2) and 3) really make me feel a bit strange since the
FilterOperandFromlstColumnId_New(post back event handler) should always
fire after Page_load. I think this is an abnormal behavior. Anyway, I'll do
a test on my local side first and will update you soon.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #6
Hi Oliver,

After some tests on my local side, seems the Event sequence are always as
we normally expected:

Contro's creation events ----> Page_Load/Control's Load events ---->
PostBack events

Also, below is my simple test page, which output
=============
dgEvent_ItemCreated get called!
dgEvent_ItemCreated get called!
dgEvent_ItemCreated get called!
Page_Load get called!
=============

you can also have a test on your side to see whether you still get the
strange event sequence.
=============aspx===========
<HTML>
<HEAD>
<title>datagridfooterevent</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="dgEvent" runat="server" AutoGenerateColumns="False"
ShowFooter="True">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox id=txtString Text="<%# Container.DataItem %>"
Runat="server">
</asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="lstEvent" Runat="server" AutoPostBack="True"
OnSelectedIndexChanged="lstEvent_SelectedIndexChan ged">
<asp:ListItem Value="aaa">aaa</asp:ListItem>
<asp:ListItem Value="bbb">bbb</asp:ListItem>
<asp:ListItem Value="ccc">ccc</asp:ListItem>
<asp:ListItem Value="ddd">ddd</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
=====================
-===============codebehind=============
public class datagridfooterevent : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgEvent;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
this.dgEvent.DataSource = new
string[]{"aaa","bbb","ccc","ddd","eee","fff"};
this.dgEvent.DataBind();
}
Response.Write("<br>Page_Load get called!");
}

//form generated code.................
protected void lstEvent_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Response.Write("<br>lstEvent_SelectedIndexChanged get called!");
}

private void dgEvent_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Response.Write("<br>dgEvent_ItemCreated get called!");
}
}
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #7

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

Similar topics

16
by: thejackofall | last post by:
Hi. I have a button called btnSelect on a web form. There is a handler for it. However, the Page_Load() gets called before the handler gets called. I want to do the following. In the...
2
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
2
by: John Dalberg | last post by:
I need to know what happens after Page_load has finished so I put a breakpoint at the last statement. However after stepping into after this last statement, the app continues running without the...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
1
by: choukrou | last post by:
Hello everybody! Got a nice problem on 1 of my aspx (and only one): It was working "perfectly" for 1year and a half. Last week I had to fix a lil bug. I do that and test my app. And on the fixed...
5
by: Jason Huang | last post by:
Hi, In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox control txtBox1, 1 Button control Btn1, and 1 GridView control GV1. I found whenever I click the Button control Btn1, then...
3
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
In the page_load event i need to see which event fired the post back. what here allows this. I specificly want to know if the enter key was pressed. but i need to check for others. -- (i''ll be...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.