CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    [RESOLVED] need back button listener method

    Hello,

    Is there a way in the C# codebehind to setup a method that gets called when the user goes to the page from a back button press? For example, user is on page A, clicks a link to go to page B, then presses back button to return to page A. The codebehind on page A responds with something like backButton_Click() and carries out the desired proceedure.

    I ask this because the Page_Load() method for page A is not invoked from back button presses, so I need something else.

    Thanks

  2. #2
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: need back button listener method

    Can you handle the back button click event and check whether the current page loaded is Page A or Page B? Or maybe the page to be loaded is Page A?
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  3. #3
    Join Date
    Nov 2011
    Posts
    63

    Re: need back button listener method

    The page to be loaded is page A. It needs to run the BackButton_Click() method on page load (just like Page_Load() would). I don't know how to do this.

  4. #4
    Join Date
    Dec 2011
    Posts
    61

    Re: need back button listener method

    first use this code to disable browser cache:
    Code:
    Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));  
    Response.Cache.SetCacheability(HttpCacheability.NoCache);  
    Response.Cache.SetNoStore();
    then use Session or other way to tell if the user access Page A for the first time or not. If not, then trigger some code in Page_Load().

    Note server side has no way to tell if the user go back to Page A by clicking the back button or by retying the url, as all this happens at client side.

  5. #5
    Join Date
    Nov 2011
    Posts
    63

    Re: need back button listener method

    Setting the cacheability to nocache seems to work. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured