Call c# method inside "onbeforeunload" event JS RRS feed

  • Question

  • Hi guys!

    [EDIT] I dont know if I post in the correct forum. Sorry. [/EDIT]

    I have a Default.aspx that I implemented the code below. Inside this event I need call a C# method to unlink the current client that close the browser.

        <script language="javascript" type="text/javascript">
            window.onbeforeunload = function (event) {

    My method is on Default.aspx.cs and call "UnlinkOperator" like below. Is a static void method because dont need return a value.

            public static void UnlinkOperator()
                // O evento Session_End é disparado quando uma sessão do usuário finalizada ou é expirada.
                Socket socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                ncConfigBLL objConfiguracaoBLL = new ncConfigBLL();
                ncConfiguracao objConfiguracao = new ncConfiguracao();
                objConfiguracao = objConfiguracaoBLL.ConsultaServidor(objSessao);
                EndPoint endPoint;
                if (string.IsNullOrWhiteSpace(objConfiguracao.ServidorAplicacaoIP) || objConfiguracao.ServidorAplicacaoPorta < 0)
                    endPoint = new IPEndPoint(IPAddress.Parse(""), 0);
                    endPoint = new IPEndPoint(IPAddress.Parse(objConfiguracao.ServidorAplicacaoIP), objConfiguracao.ServidorAplicacaoPorta);
                byte[] mensagem = Encoding.Default.GetBytes("<NCAC_OPERADOR" + objSessao.SessionID.ToString().PadRight(100, ' ') + ">");
                socketSend.SendTo(mensagem, mensagem.Length, SocketFlags.None, endPoint);

    I tried use ajax, javaScript and a lot of things to call but all without success. I hope that somebody can help me!

    Thank you!

    Atenciosamente, Seratti.

    • Edited by Seratti Monday, February 17, 2014 12:04 PM [EDIT]
    • Moved by Caillen Tuesday, February 18, 2014 7:41 AM
    Monday, February 17, 2014 12:02 PM

All replies

  • Hi Seratti,

    Please post in ASP.NET forum where you could get better responses.

    Thanks for your understanding.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 18, 2014 7:41 AM