0

I want to update DB when the user closes the browser. I am capturing it in windows.onbeforeunload in javascript . I want to call a function in server side when the when the on before unload event and update the DB.

I am using asp.net 2.0 Framework and don't have ajax installed in my system. So I scriptmanager is not recognized by asp.

Can I have any other way to call a server side function from javascript without using script manager or pagemethods. Please help!!!!

1
  • I installed ajax 1.0 on the system but what is happening is onunload function is working in master page but i cant use page method from there and onunload fucntion is not working in the content pages. Commented Jan 27, 2014 at 11:44

2 Answers 2

1

Use following code is asp.net client side :

      <script>
            function CallServerMethod() {
                alert("<%= GetValue("  karthick  ") %>");
            }
     </script>

then write code on asp.net button as OnClientClick="CallServerMethod();" i.e

<asp:Button ID="Button1" runat="server" OnClientClick="CallServerMethod();" Text="Button" />

In code behind . i.e .cs page declare the function GetValue() as below

        public String GetValue(string myval)
        {
            return myval;
        }

as soon as you click then GetValue() you will see alert box.

Sign up to request clarification or add additional context in comments.

1 Comment

hay shakir can you please help me to do so.?
0

I suppose you could try using the jQuery post method. You could even post to a different page and pass any arguments you need to do the DB update.

1 Comment

I have installed ajax 2.0 but i am not able to get script manager tag working. its giving error

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.