Search code examples
c#asp.netscriptmanagerpagemethods

PageMethods.Method not being called from javascript


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);
        }
    }

Solution

  • 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.