Solved

To fire one event upon going to previous page

Posted on 2014-03-02
11
46 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
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
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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
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
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 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 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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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