Simple Page Method in asp.net

On May 29

Simple Page Method in asp.net

Following is the Code for async PageMethod call in asp.net :

HTML :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">

        function asyncmethod() {
            PageMethods.set_path('<%=ResolveUrl("~/Default.aspx")%>');
            PageMethods.Async_Method("a", OnOk);
            
            //PageMethods.Insert_UserPD(document.getElementById('name').value, strCity, strCity_id, document.getElementById('mob_no').value, document.getElementById('verify_code').value, document.getElementById('email').value, '0', 'Browser', OnOk);

        }

        function OnOk(response) {
        alert(response);
        }
        
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div>
        <input id="Button1" type="button" value="button" onclick="asyncmethod()" />
    
    </div>
    </form>
</body>
</html>

Code Behind (.cs file) :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    [System.Web.Services.WebMethod()]
    [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
    public static string Async_Method(string p1)
    {
        return p1+"b";
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}



Responses

Nice

Yes, really goodone.

Could have been better.

Cool.

?

Leave your comment