Please help me understand this PostBack Issue

N

needin4mation

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.
 
N

needin4mation

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.
 
N

needin4mation

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!
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top