Solved

To fire one event upon going to previous page

Posted on 2014-03-02
11
37 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I do want to call one code-behind event within func1.
0
 
LVL 27

Expert Comment

by:Sammy
Comment Utility
Good luck with that.
0
 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
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
Comment Utility
Any other help? Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 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

17 Experts available now in Live!

Get 1:1 Help Now