locked
Page reload data issue RRS feed

  • Question

  • User-1100884601 posted

    Hi, 

    I have form and submit button , on submit button click  i have shown one alert and then its going to server side function to save the form data. on save button clicks page reloads but it always load the old data, however data is getting saved in db.  

    i used this inside button on-client click    <asp:Button ID="btnSave" runat="server"   OnClientClickTick="return SaveConfirm();"  Onclick="SaveData"></asp:Button>

    function SaveConfirm{

    alert('Your progress has been saved');
    window.location.href = window.location;

    c# code 

    protected  void SaveData(){   // here i written code to save the data in db which works fine and save data

    }

    To reproduce the issue please follow the steps 

    1. Open this page    https://techdev1.boardevaluations.com/Survey.aspx?s=fe1bbde95f9241fb86a95632f65f3a85&i=b23d5de3ec904445ac78d3e723639c87
    2. scroll bottom and enter some data in textarea  and  click on Save button 
    3. page reloads on save button click but it loads old value,  again when you manually refresh the page then it shows  show new value 

    I want here on save button clicks it should reloads with current new value.  if anyone have solution, please help me. 

    Thanks in advance

    Thursday, August 22, 2019 4:37 PM

All replies

  • User409696431 posted

    Remove window.location.href = window.location; from the alert function, and rely on reloading the data on postback.

    Thursday, August 22, 2019 7:08 PM
  • User-1100884601 posted

    I am using this below code but i dont why its never working, 

     

     System.Text.StringBuilder sb = new System.Text.StringBuilder();
      sb.Append("<script language='javascript'>function ChangeColor() {");
      sb.Append("window.location.href = window.location; ");
      sb.Append("}</script>");
    
     //Render the function definition. 
     if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
      {
       ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", sb.ToString());
      }
    
    //Render the function invocation. 
    string funcCall = "<script language='javascript'>ChangeColor();</script>";
    
      if (!ClientScript.IsStartupScriptRegistered("JSScript"))
       {
            ClientScript.RegisterStartupScript(this.GetType(), "JSScript", funcCall);
        }
    

    Thursday, August 22, 2019 7:56 PM
  • User409696431 posted

    A javascript window.location.href = windows.location does not go to the server and fetch new data.  It loads the page from the browser's cache.  Since you want to reload the page from the server, why use that?  The save button does a post back.  Use "IsPostBack" in the code behind page to reload the data, if it needs special handling and won't fetch new data on each load.

    Thursday, August 22, 2019 8:30 PM