2

I'm just new ASP .NET, and I would like to know on how can I clear all the data entries after saving it and redirected to other page?

I have tried this on my HTML page,

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

and also this on my Code Behind page,

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            Response.Cache.SetCacheability(HttpCacheability.Server);
            Response.Expires = -1;
            Response.AddHeader("Pragma", "No-Cache");
            Response.CacheControl = "no-cache";
        }
    }

but still the data I encoded / page appears whenever I go back.

Please help. Greatly appreciate. Thank you. :D

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
pampi
  • 517
  • 4
  • 8

2 Answers2

1

It should be:

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
  • I go from other page but after I click 'BACK' still the page was populated. I wanted the page1 after I go to page2, and I click back the page1 will turns to its original view. Thx for the help anyways. – pampi Feb 11 '13 at 09:38
0

If you don't want the browser to keep form fields populated, you can set the HTML attribute autocomplete to off.

<input type="text" name="myfield" autocomplete="off" />
Matthew
  • 24,703
  • 9
  • 76
  • 110
  • I go from other page but after I click 'BACK' still the page was populated. I wanted the page1 after I go to page2, and I click back the page1 will turns to its original view. Thx for the help anyways. – pampi Feb 11 '13 at 09:39