asp.net - Call a method in an aspx page -


can call method in asp.net web page (in aspx.cs page) without checking in pageload?

for example '../test2.aspx/testmethod

in this link have noticed can give url: "pagename.aspx/methodname", in jquery ajax method. have tried , never works me.

page methods new mechanism in asp.net application server code cab bound asp.net pages

to enable page methods need drag scriptmanager control page , mark
enablepagemethods “true”.

    <asp:scriptmanager id="scriptmanager1" runat="server"             enablepagemethods="true">     </asp:scriptmanager> 

go code behind file of page , add static method

    [webmethod]     public static string helloworld(string name)     {        return string.format("hi {0}",name);     } 

in javascript function can use pagemethods object call webmethod of page.

    <script type="text/javascript">     function greetingsfromserver() {        var name = 'jalpesh';        pagemethods.helloworld(name,onsuccess, onerror);        return false;    }    function onsuccess(response) {        alert(response);    }    function onerror(error) {        alert(error);    }    </script> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -