Skip to content Skip to sidebar Skip to footer

Page_load Is Been Fired When Webmethod Is Called Through Javascript Pagemethods

I have an aspx page. I've added a ScriptManager to it, and set EnablePageMethods=true, and created a static method marked as [WebMethod] on the server-side. I have always worked w

Solution 1:

So after founding the culprit of why controls in my update panel was calling post back twice I found it was because of a page method being called.

After finding LcSalazar solution I did disabled Friendly URLs and everything was working. But I find the Friendly URLs to be more clean so I found a solution .

On your master page add the following .

<scripttype="text/javascript">
        $(function () {
            try {
                if (PageMethods.get_path().indexOf('.aspx') == -1)
                    PageMethods.set_path(PageMethods.get_path() + '.aspx');
            } catch (e) {

            }
        })

    </script>

Once the page methods path includes the .aspx the page_load doesn't fire again.

Alternatively look into using ASP.Net Web Api . Better practice as well when it comes to reusable methods instead of declaring the methods in you Base Page or every page you are trying to use it .

Solution 2:

I discovered that the problem on my case is that I'm using friendly URL's. Since PageMethods references the server-side page by its address, there you have the issue. It's been discussed here, on CodePlex: http://aspnetfriendlyurls.codeplex.com/workitem/3. Apparently there are workarounds for this, but I ended up making a manual ajax call to a generic handler (.ashx).

Solution 3:

When you submit a form that has runat server it processes the full .net lifecycle. Which fires the Page_Load of your .cs class. If you want to make it strictly want to fire the webmethod I suggest using an ajax call to your webmethod.

Solution 4:

Disable friendly urls. Comment this out in App_Start\RouteConfig.cs routes.EnableFriendlyUrls(settings);

Post a Comment for "Page_load Is Been Fired When Webmethod Is Called Through Javascript Pagemethods"