Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 53
  • Last Modified:

To fire one event upon going to previous page

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?
0
HuaMinChen
Asked:
HuaMinChen
  • 6
  • 5
1 Solution
 
Sammy AgeilCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor 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?
0
 
Sammy AgeilCommented:
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 :-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HuaMinChenBusiness AnalystAuthor 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.
0
 
Sammy AgeilCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor 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

0
 
Sammy AgeilCommented:
You can't call code behind from a client code.
You will have to call the client code from your code behind.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Sorry, I do want to call one code-behind event within func1.
0
 
Sammy AgeilCommented:
Good luck with that.
0
 
HuaMinChenBusiness AnalystAuthor 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?
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Any other help? Thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now