13 Oct 2011

Page Methods

Design
<asp:ScriptManager id="SM1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
    </asp:ScriptManager>

PageMethods.getDistance(fromto,OnSuccess,OnError);

function OnSuccess(result)
    {
        if (result==null)
        {
        }
        else
        {
            txtKM.value=result;
        }
    }
    function OnError(err)
    {

    }

code behind

<System.Web.Services.WebMethod()> _
Public Shared Function getDistance(ByVal FromTo As String) As String
        Try

            Dim CityFrom, CityTo As Integer
            CityFrom = Val(FromTo.Split("|")(0))
            CityTo = Val(FromTo.Split("|")(1))

            Dim db As DBAccess = New DBAccess

            db.AddParameter("@Case", 7)
            db.AddParameter("@PlaceFrom", CityFrom)
            db.AddParameter("@PlaceTo", CityTo)

            Dim dt As DataTable
            dt = db.ExecuteDataTable(, "usp_LTC")
            If dt.Rows.Count = 0 Then
                Return ""
            Else
                Return dt.Rows(0)(0)
            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Function

No comments:

Post a Comment