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)
    {

    }
}

You may also like :

Basic steps to implement ASP dotnet MVC using Entity Framework Code First approach
SQL Query to Release lock on database
How to change URL withought page postback
Csharp Code to make call By connecting you phone to PC
BE Electronics ETC IT Computer Project Titles - Group 1
SQL Query to Split string by specific seperator
Simple Page Method in asp.net
Error 720 Resolution
Queries in LINQ to DataSet
BEWARE-XSS THIEVES ARE LOOKING FOR YOU
how to search date within range in c Sharp dot net and mssql

You may also like :





Responses