Error "Unknown Web Method" after Server.Transfer

I am using System.Web.Services.WebMethodAttribute to make a public static method of an ASP.NET page called from the client side script:

test.aspx.cs

[System.Web.Services.WebMethod]
public static string GetResult()
{
    return "result";
}

      

test.aspx

<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" />

<script type="text/javascript">
    alert(PageMethods.GetResult());
</script>

      

The method works as it should, but if I load test.aspx with

Server.Transfer("test.aspx");

      

I am getting an "Unknown Web Method" error. After

Response.Redirect("test.aspx");

      

the page works well.

Could you please tell me what is causing the error and how you can avoid it? Many thanks!

+1


source to share


3 answers


It seems that calling set_path solves the problem:



<script type="text/javascript">
    PageMethods.set_path("test.aspx");
    alert(PageMethods.GetResult());
</script>

      

0


source


Where do you get the error message - server or client?



If it's on the client, see what it is trying to do. I suspect you will find that it is asking for the original page and not test.aspx.

+1


source


Server.Transfer shifts the page processing (at the server level) to the page you specified, however the browser thinks you are still on the original page:

So, for example, you are at start.aspx and in the code behind you have Server.Transfer ("test.aspx");

Your browser thinks you are still at start.aspx and javascript will send requests for page methods at start.aspx.

With Response.Redirect, your browser knows you are currently on test.aspx and requests are being sent correctly.

+1


source







All Articles