1 Replies - 1988 Views - Last Post: 15 November 2012 - 08:00 AM Rate Topic: -----

#1 xLilHoPpinG  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 09-September 09

Javascript Async Postback

Posted 15 November 2012 - 02:21 AM

Dear all members

I have a question on this problem upon clicking a link 2 times it will clear the session , the thing i want to do here is to record a log of the user logging in and out , but the scenario is what if the user did not manually log out (e.g clicking on the "X" button of the browser or pressing Alt+F4) i would also want to record this as log out into the database.I have already found a method for it but however clicking on a link 2 times causes it to clear the session automatically.

Buttons work perfectly no matter how many times i click on the button but the Menu Item does not work perfectly.

This is the links i used :

http://forums.asp.ne...18974.aspx/1/10


What i would have thought is because of Async Postback that causes it to be like this.Please advice me.

  <script type="text/javascript">
<!--
            getAjaxValues = function (webUrl) {
                var xmlHttpObject = null;

                try {
                    // Firefox, Opera 8.0+, Safari...

                    xmlHttpObject = new XMLHttpRequest();
                }
                catch (ex) {
                    // Internet Explorer...

                    try {
                        xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
                    }
                    catch (ex) {
                        xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
                    }
                }

                if (xmlHttpObject == null) {
                    window.alert('AJAX is not available in this browser');
                    return;
                }

                xmlHttpObject.open("GET", webUrl, false);
                xmlHttpObject.send();

                var xmlText = xmlHttpObject.responseText;


                return xmlText;
            }

</script>

<script type="text/javascript">
<!--
        //The variable "g_isPostBack" is always "false" , only when at code-behind on Page_Load it would be true.It //will not log out if it is true.
        var g_isPostBack = false;
        window.onbeforeunload = function () {
            if (g_isPostBack == true)
                return;

            window.onunload = function () {
                var webUrl = 'LogOut.aspx';
                var returnCode = getAjaxValues(webUrl);
                //alert(returnCode);

            }
        }
    
</script>


I was wondering what have i done wrong above? Why wouldn't it work since in debug mode it actually went pass the "RegisteronsubmitStatement" method.
On the Page_Load of the page at code behind i would do this , this is a ASP.NET VB.NET Programming Language but the main problem i think is at the javascript:

Page.ClientScript.RegisteronsubmitStatement(Me.GetType(), "onsubmitScript", "g_isPostBack = true;")



Please guide me thank you.

This post has been edited by xLilHoPpinG: 15 November 2012 - 05:17 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript Async Postback

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Javascript Async Postback

Posted 15 November 2012 - 08:00 AM

Think we'll move this to ASP.NET
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1