Friday, March 16, 2012

Please help me understand this PostBack Issue

I am inserting a row in a database. All that works fine. What I now
need is the last inserted id from the database. I can get that. Again
all working.

Then what I need to have is that same last inserted id key to be
available when the page reloads. When I press the button to insert the
data, I can do this:

Session("last")=LAST_ID;
Response.Write("My row id is: " + Session("last"));
//this works and is inside my INSERT button_click event

But when the Page_Load comes back I cannot see it. I try this:

if (Page.IsPostBack)
Response.Write("My row upon postback is: " + Session("last"));
//this fails upon postback in the Page_Load

It is just blank. Nothing there.

Instead of a Session variable, I have tried a static variable, (I think
ViewState, but am not sure), a global variable, nothing holds the data
upon PostBack.

Thank you for any help.And what I don't get is that when I do a trace it shows my INSERT code
in the Begin PostBack which looks like I would have access to the
variable.
I'm sorry to keep responding to myself, but it looks like the lifecycle
is as follows:

Page_Load
Button_click

So,

Page_Load fails to show a Session Variable or any other because it has
not been initialized yet.
Button_click is where the row is inserted and the last ID is given.

But because the Button_click has fired after the Page_load the
page_load never sees the value.

So I must find a way to get the last row id..oh wait..I populate the
controls after the insert in that click event instead of the Page_Load
event.

Thanks!
Umm, glad to be of assistance? :)

Mythran
needin4mation@.gmail.com wrote:

> I'm sorry to keep responding to myself, but it looks like the
> lifecycle is as follows:
> Page_Load
> Button_click

RTM...

http://msdn.microsoft.com/library/d...y/en-us/cpguide
/html/cpconControlExecutionLifecycle.asp

;-)

--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

0 comments:

Post a Comment