I am trying to have value only generated once on page load but cause page load and page init is called every time a user hits f5 im not sure how to stop it being created every time.
public string caseReference
{
get { return (string)ViewState["preAppointmentCaseRefrence"] ?? string.Empty; }
set { ViewState["preAppointmentCaseRefrence"] = value; }
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
caseReference = _dal.GetPrefix("VAULTX");
}
}
The probelm that i have is the next id has to be written back to the db asap so that cannot be delayed
Unclear you meant that _dal.GetPrefix("VAULTX"); returns a new db generated id and that you keep that using the viewstate until the final db operation? IMO the id should be generared just before being actually used (ie at the time of the db insert).
Here it seems you are working against how the web works rather than with it (basically F5 does the same GET request again and typically you would have then to understand if this is the "first" one or if it should be considered as a "new" one etc... maybe
through something really complex).
In short try to solve the real problem. Here it seems your current design causes a problem and rather than changing your current design, you try to take more steps to "undo" the conséquences of this problem rather than really to solve it.
Member
15 Points
99 Posts
How do i stop value changing on readlo or F5 of page
Oct 21, 2016 08:37 AM|rogue1|LINK
I am trying to have value only generated once on page load but cause page load and page init is called every time a user hits f5 im not sure how to stop it being created every time.
The probelm that i have is the next id has to be written back to the db asap so that cannot be delayed
All-Star
48710 Points
18180 Posts
Re: How do i stop value changing on readlo or F5 of page
Oct 21, 2016 09:20 AM|PatriceSc|LINK
Hi,
Unclear you meant that _dal.GetPrefix("VAULTX"); returns a new db generated id and that you keep that using the viewstate until the final db operation? IMO the id should be generared just before being actually used (ie at the time of the db insert).
Here it seems you are working against how the web works rather than with it (basically F5 does the same GET request again and typically you would have then to understand if this is the "first" one or if it should be considered as a "new" one etc... maybe through something really complex).
In short try to solve the real problem. Here it seems your current design causes a problem and rather than changing your current design, you try to take more steps to "undo" the conséquences of this problem rather than really to solve it.