locked
How do i stop value changing on readlo or F5 of page RRS feed

  • Question

  • User-1821202846 posted

    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

    Friday, October 21, 2016 8:37 AM

All replies

  • User753101303 posted

    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.

    Friday, October 21, 2016 9:20 AM