Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page load is fired instead of web method

OK, so my websites been working normally up until now, I'm not really sure what I've changed. I have a jQuery AJAX call that sends a coupon code to the server, and retrieves a number (which is the discount).

The Webmethod is no longer being fired though, instead the Page_load of the page which the webmethod is on is being fired. Why? What can I check? What can I do?

Here is my handler for when the button is clicked

$('div#code_apply_btn').click(function() {
    $(this).html('PLEASE WAIT');
    getpromocode();
});

Here is the AJAX call

function getpromocode(){
    var pcode = $('input#input_circuitcode').val();
    var hid = parseInt($('input#ss_id_h').val());
    $.ajax({
        type: "POST",
        url: "register.aspx/get_promocode",
        data: '{"promo":"' + pcode + '", "uid":' + hid + '}',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (msg) {
            if (msg.d != -1) {
                applydiscount(msg.d);
                $('div#reg_circuit').show();
                $('div#circuit_promo').hide();
                $('div#reg_circuit').click();
            }
            else {
                $('input#input_circuitcode').val('');
                $('div#code_apply_btn').html('APPLY CODE');
            }
        },
        error: function (msg) {
            alert(msg);
        }
    });
}

Here's the webmethod

[WebMethod]
public static int get_promocode(string promo, int uid)
{
    return DAC.GetPromoCode(promo);
}

The webmethod is never called, but the Page_load event fires and runs through everything then it gets a 500 error because it shouldn't be called and doesn't have all the data it needs.

EDIT:

All my other pages that are using web methods work fine. It's just this page.

Another bit of strange behaviour: In chrome as soon as I begin to type "register.aspx", the Page_load is called. Again all my other pages are fine and this doesn't happen.

like image 201
James Hay Avatar asked Sep 16 '25 00:09

James Hay


2 Answers

I have found the answer to my question:

Because I have VS2008 I can only use .Net 3.5. My server however has .Net 4.0 or 2.0 for whatever reason I can't choose 3.5 as I would have liked to. So everytime I move my project I have to change the web.config because the default 3.5 config is filled with a whole bunch of stuff that 4.0 doesn't like.

So I remembered that I had emptied out the web.config to a barebone version that still worked in 3.5 which is where the problem is. I narrowed it down to these lines which I had excluded from the version running locally on 3.5

<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, 
        System.Web.Extensions, Version=3.5.0.0, Culture=neutral, 
        PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

I guess the script module is what passes your jQuery requests to the web methods rather than the default page handler. There you go.. But no obvious errors or anything, it just didn't work.

like image 174
James Hay Avatar answered Sep 18 '25 16:09

James Hay


You must have EnablePageMethods="true" in ScriptManager on that page.

like image 37
Antonio Bakula Avatar answered Sep 18 '25 15:09

Antonio Bakula