Specializations

Wednesday, November 14, 2012

webmethod or pagemethod calling

ASP.NET

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" ScriptMode="Release"
        EnablePartialRendering="true" LoasdScriptsBeforeUI="false">
</asp:ScriptManager>
<asp:TextBox ID="txtExporter" runat="server" Width="100px" CssClass="textbox" onchange="SelectExportesStmt();"></asp:TextBox>
JAVASCRIPT
function SelectExportesStmt()
       {
        var txtExporter = document.getElementById('<%=txtExporter.ClientID %>');
                if (txtExporter.value != '')
                PageMethods.GetExporter(txtExporter.value, OnExporterSuccess, OnFailure);
       }
 funcation OnExporterSuccess(exprt)
{
}
 funcation OnFailure(error)
{
alert(error);
}
 c#.net
[WebMethod]
 public static string GetExporter(string sPtnrCodeDetails)
        {
            try
            {

              }
catch{
}
}
Use javascript code or JQuery script
 JQUERY
function getECCNValidations(){    
            $.ajax({
                    type: "POST",
                    url: "SalesOrder.aspx/GetECCNDetails",
                    contentType: "application/json; charset=utf-8",
                    data: "{'sECCN':'" + $('#<%=txtECCN.ClientID%>').val() + "'}",
                    dataType: "json",
                    success: function (ECCN) {                      
                               if(ECCN.d=='') {
                                   alert("Please Enter Valid ECCN Code");
                                   $('#<%=txtECCN.ClientID%>').val('');
                                   $('#<%=txtECCN.ClientID%>').focus();
                                   return false;
                               }                                
                               $('#<%=txtLicenseType.ClientID %>').focus();
                            },
                    failure: function (error) {
                             alert(error);      
                             return false;
                          }
                });
     }

No comments:

Post a Comment