Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Calling c# method using JavaScript in ascx page

$
0
0
<div class="votingouterbox"> <div class="voting">Hi,</div> </div> <div class="messageContent"> <div class="container"> <div class="body">

I am using SharePoint Visual webpart where in I have to use JavaScript or JQuery to call c# method on drop down selected index change to avoid postback.

I have used following code

<asp:DropDownList ID="drpClient" runat="server" DataTextField="ClientName" DataValueField="ClientID" onchange="GetCountryDetails()"></asp:DropDownList>

Below is the JavaScript function.

 <script type="text/javascript">

 function GetCountryDetails() {             debugger;                       var parm = document.getElementById('<%= drpClient.ClientID %>');             var strCountry = parm.options[parm.selectedIndex].text;             var SelectedText = strCountry;             var SelectedVal = parm.options[parm.selectedIndex].value;

            alert(SelectedVal);

                             $.ajax({                     type: "POST",                     url: 'Client.aspx/GetPreviousMonthServiceData1',                     data: "",                     contentType: "application/json; charset=utf-8",                     dataType: "json",                     success: function (result) {                         if (CallBackFunction != null && typeof CallBackFunction != 'undefined') {                             CallBackFunction(result);                         }

                    },                     error: function (result) {                         alert('error occured');                         alert(result.responseText);                         //window.location.href = "FrmError.aspx?Exception=" + result.responseText;                    },                     async: true                 });                      }

    </script>

C# code in ascx.cs  is:

publicstaticvoidGetPreviousMonthServiceData1()

        {

        }

It is not working... It always throws exception saying - Unknown Web method...

</div> </div> </div>

Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>