Solved

To fire one event upon going to previous page

Posted on 2014-03-02
11
40 Views
Last Modified: 2015-09-10
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
Comment
Question by:HuaMinChen
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 39899712
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39899743
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
 
LVL 27

Expert Comment

by:Sammy
ID: 39899756
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39899767
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
 
LVL 27

Expert Comment

by:Sammy
ID: 39899797
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 10

Author Comment

by:HuaMinChen
ID: 39899820
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
 
LVL 27

Accepted Solution

by:
Sammy earned 140 total points
ID: 39899871
You can't call code behind from a client code.
You will have to call the client code from your code behind.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39899902
Sorry, I do want to call one code-behind event within func1.
0
 
LVL 27

Expert Comment

by:Sammy
ID: 39899906
Good luck with that.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39899921
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39902339
Any other help? Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help parsing JSON in my VB.Net application 4 45
Error in page 3 46
Replace &lt; with < 14 56
rest webservice call over https via c# 6 25
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to dynamically set the form action using jQuery.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now