0

I want to get access to a method in code behind when I clicked an span in my view aspx:

DEFAULT.ASPX VIEW CODE:

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<%-- MY SPAN --%>
 <span runat="server" onclick="ShowChartSpider(this.id)" id="group_2" style="cursor: pointer" class="pull-right">My Span</span>


<%-- JAVASCRIPT CODE --%>
    <script type="text/javascript">
        function ShowChartSpider(group_id) {

            $.ajax({
                type: "POST",
                url: "Default.aspx/MethodToCreateChart",
                dataType: "json",
                data: "{'parameter1':" + JSON.stringify(group_id) + "}",
                contentType: "application/json; charset=utf-8",                

                success: function (data) {
                    alert("all correct");
                },
                error: function (data) {
                    alert("no");
                }
            }
            );
        }
    </script>
</asp:Content>

DEFAULT.ASPX.VB CODE BEHIND:

<WebMethod()>
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
    Public Shared Sub MethodToCreateChart(sender As Object, e As EventArgs)
        ' My code to create the chart .....
    End Sub

if I run the page, and inspects the page with the browser to see errors, none appear, but the code does not reach the breakpoint that I put in the method in codebehind.

What I´m doing wrong? I would appreciate suggestions, thanks.

Esraa_92
  • 1,558
  • 2
  • 21
  • 48

4 Answers4

1

First check your server allow non HTTPS request. i had that type of issue and my server didn't allow me to do that. it so then disable that and test.

Then check the response status.

error: function(xhr, status) {
alert(xhr.status); }

let us know that is the outcome.

--Ruhul

  • 1
    I get the alert for success, not for error, but what I said, the code does not reach the breakpoint that I put in the method in codebehind. :-( – Esraa_92 Oct 07 '16 at 09:13
1

Go to "RouteConfig.vb" under "App_Start" folder.

Change following line

 settings.AutoRedirectMode = RedirectMode.Permanent

To

settings.AutoRedirectMode = RedirectMode.Off

i think your method code returning something like this.

Return Default.aspx/MethodToCreateChart

so me your MethodToCreateChart logic.

you can try with below sample method. your internal server error are coming because you are returning somethng from your method.

Public Shared Function MethodToCreateChart(parameter1 As String) As String

   Return "Hello " & Environment.NewLine & "The Current Time is: " & _DateTime.Now.ToString()
End Function
0

I think you should remove 'runat=server' attribute from span tag.

Amin
  • 221
  • 3
  • 13
0

You use aspx file same as ashx files. So have a look at below links: 1. How do you debug ASP.net HTTPHandler 2. Can't debug ASHX handler

Community
  • 1
  • 1
Amin
  • 221
  • 3
  • 13