简体   繁体   中英

Call a server side function from javascript in asp.net 2.0 without using script manager or pagemethods

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!!!!

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();" ie

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

In code behind . ie .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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM