Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

To fire one event upon going to previous page

Posted on 2014-03-02
11
Medium Priority
?
51 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:Sammy Ageil
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 11

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 Ageil
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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
LVL 11

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 Ageil
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
 
LVL 11

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 Ageil earned 280 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 11

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 Ageil
ID: 39899906
Good luck with that.
0
 
LVL 11

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 11

Author Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

715 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