To fire one event upon going to previous page

HuaMin Chen
HuaMin Chen used Ask the Experts™
on
Hi,

We do press Alt-Left Arrow, to locate to previous web page. Upon doing that, can we fire one event, before going to the previous page?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The only event is window.onbeforeunload
however, this event is triggered in many other cases, when user try to exit the page or close the browser or event navigate to a different page.

window.onbeforeunload = function() { return "Bye."; };

there has always been lots of debates about using this functionality on browsers,
here is how to *disable it* http://viralpatel.net/blogs/disable-back-button-browser-javascript/

and more info http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
HuaMin ChenProblem resolver

Author

Commented:
Many thanks.
Within this
    ...
    <script type="text/javascript">
        window.onbeforeunload=function {

        }
        ...

Open in new window

I want to execute one event from code-behind. how?
This is a client event, the only way to execute it is by sending back
in your aspx page create a function like so
<script type="text/javascript">
 window.onbeforeunload = myFunction;
function myFunction()
{
   // your functionality here
}
</script>

Open in new window

and in your page load add this

Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","myFunction()",true);

Open in new window


I am outta here Good luck :-)
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

HuaMin ChenProblem resolver

Author

Commented:
No, I mean within func1 below

    <script type="text/javascript">
        window.onbeforeunload=func1;
        function func1() {

        }
        ...

Open in new window

I want to execute/call one code-behind event.
Change myFuction to func1 in the code above.
The line start with Page is code behind and you can use it in your page load event
HuaMin ChenProblem resolver

Author

Commented:
I have one event which is existing within Code-behind. How to call it within func1 below?

    <script type="text/javascript">
        window.onbeforeunload=func1;
        function func1() {

        }
        ...

Open in new window

You can't call code behind from a client code.
You will have to call the client code from your code behind.
HuaMin ChenProblem resolver

Author

Commented:
Sorry, I do want to call one code-behind event within func1.
Good luck with that.
HuaMin ChenProblem resolver

Author

Commented:
Within OnClick event of the button of a Panel, we can call one code-behind event. why can't we do the same within func1?
HuaMin ChenProblem resolver

Author

Commented:
Any other help? Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial