Jump to content

Search the Community

Showing results for tags 'asp.net javascript html DOM'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Found 1 result

  1. Wylbur

    Back Button Blues

    Hi;I'm developing a web app in ASP.NET that loads controlsdynamically on a page (depending upon user responses).Handling the back button has been giving me fits.Apparently, there is no handler for that.(If I'm wrong about that, then PLEASE correct me.)What I want to do is to trigger a postback on the back button.(This must be done. There are no alternatives.)I'm trying to detect the "back button state" to accomplish this.The first thing I tried was to keep a running count ofrequest/response cycles and comparing it to window.history.length.If the two are different, then it might be assumed that the backbutton had been clicked.That didn't work. On the first back button click, both countsincreased, remaining equal.My next idea was to write Javascript code to a label that willset a boolean to true if a postback has occurred.In my Page_Load handler, I have the following: this.lblJavaScript.EnableViewState = false; this.lblJavaScript.InnerText = "postback_made = true;";This is the tag for the element: <span class="CI12_test" id="lblJavaScript" name="lblJavaScript" runat="server"></span>(This tag is positioned above the form and within the body.)In the function that handles the onload event in Javascript,I have the following: var js_code = document.getElementById("lblJavaScript").innerHTML; var ev = window.eval (js_code); document.getElementById("lblJavaScript").innerHTML = "postback_made = false;"The problem that I'm having is that, when the back button is clicked,the "lblJavaScript" element is reset to its original value("postback_made = true;"). I tried moving the code for clearing the switch into a function thathandles the "onbeforeunload(e)" event.That didn't work.(FYI: The "onbeforeunload" event fires every time, whether on a postbackor back button click.)Apparently, the values for the elements within the DOM are being cachedand reloaded on a back button event.Since I'm not quite the biggest idiot in the world, I decided that thenext thing to do would be to shut off caching. I added the following code to my Page_Load event handler: if (!IsPostBack) { Response.Buffer = true; Response.CacheControl = "no-cache"; Response.AddHeader("Pragma", "no-cache"); Response.Expires = -1441; }That does nothing.I added the following code to my Page_Load event handler:Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));Response.Cache.SetNoStore();When I clicked on the back button, I was left with "Webpage has expired".I added the following meta tags near the top of the page:<meta http-equiv="Cache-Control" content="no-cache"/><meta http-equiv="Pragma" content="no-cache"/><meta http-equiv="Expires" content="0"/>That did nothing.So the question is: How would someone determine if the page beingloaded is due to a postback or a back button click?Alternatively, how would someone force a postback on a back button click?Any advice on this would be greatly appreciated.
  • Create New...