Solved

To fire one event upon going to previous page

Posted on 2014-03-02
11
47 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
Stressed Out?

Watch some penguins on the livecam!

 
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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

631 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