0

I have a javascript function that builds a string then sends the string to the c# codebehind to work with. Problem is, the PageMethods.Method is never being called.

pertinent code:

aspx page:

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true"
    runat="server" />
<script type="text/javascript">
function makeString() {
        debugger
        var a = document.getElementById("ddlRptYear").value + "_";
        var b = document.getElementById("ddlRptType").value + "_";
        var c = document.getElementById("ddlGeography").value + "_";
        var d = "";
        var e = "";
        var x = document.getElementById("ddlTouchPoint");
        var y = document.getElementById("ddlAOR");

        if (x.disabled == false) {
            d = x.value + "_";
        }

        if (y.disabled == false) {
            e = y.value;
        }

        var pptString = a + b + c + d + e + ".ppt";
        PageMethods.GetPPTString(pptString, onSuccess, onFail);
    }

codebehind:

[System.Web.Services.WebMethod]
    public static void GetPPTString(string pptString)
    {
        if ((pptString == "") || (pptString == null))
        {
            throw new Exception("Error: No String Sent.");
        }
        else
        {
            throw new Exception(pptString);
        }
    }
todd.pund
  • 689
  • 2
  • 11
  • 36
  • How do you know it is never being called? Is it possible an exception has occurred before it even gets to the proper handler? Have you inspected the traffic to ensure the request is being sent and if so what is the response? Does the javascript throw an error before it even gets to that point? – Quintin Robinson Apr 05 '12 at 22:19
  • I know it's never being called because I stepped through the code. debugger tag in javascript and breaks in the c#. It just steps right past the call without ever going into the method. – todd.pund Apr 06 '12 at 13:58
  • Well the javascript call is async so it will naturally return execution immediately but the real question is what *is* it doing? Have you inspected the traffic and looked at what actually *is* getting sent and what *is* getting returned? Without doing that you are just going to be taking stabs in the dark and wasting your time. – Quintin Robinson Apr 06 '12 at 16:28

1 Answers1

0

I had to enable autopostback on the RadioButtonList for the SelectedIndexChanged method to be hit. It works for now, but I'll need to figure out something in the future to get past having to post back.

todd.pund
  • 689
  • 2
  • 11
  • 36