Button click event

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Is there anything wrong with the following statements?

private void btnFindCustomer_Click(object sender, System.EventArgs e)
{
storeSettings();
}

private void storeSettings()
{
Session["receivedByIndex"] = ddlReceivedBy.SelectedIndex;
}

When the page reloads after the user has clicked the button btnFindCustomer
the session object variable "receivedByIndex" is not set to an instance of
object.

Its as if the page reloads after clicking the button before the call to the
method storeSettings(), is this how its supposed to behave?

If this is the case how can I force my objects to be stored after clicking a
button before the page posts back so that I can reload them after the past
back?

Thanks
Rich.
 
Rich,

Yes, this is how it is supposed to behave. For each request to a page,
a new instance of your object is created. The state does not persist from
page request to page request.

So, in order to save state across pages, you would have to store the
values in the viewstate or in the session.

Welcome to the wonderful world of application programming across a
stateless protocol. =)

Hope this helps.
 
Back
Top