John
John

Reputation: 115

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

Upvotes: 0

Views: 2632

Answers (2)

Amol
Amol

Reputation: 11

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.

Upvotes: 1

marcin.k.nowak
marcin.k.nowak

Reputation: 26

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.

Upvotes: 0

Related Questions