Hello,
I'm using the PageMethods to call page methods. All works with the ATLAS CTP.
With the new AJAX Beta 1 I have an error: PageMethods is undefined. I don't think it's a problem of my web.config. If i create a new ASP.NET AJAX Enabled Web Site I have the same error.
Someone have the same error? Is it a bug? Is it a beta 1 change?
Thanks,
Alessadro
hello.
make sure that your page method is public and STATIC (this is a change from the previous ctp version). btw, make sure that the method receives all the values that it needs to perform its calculations since now you don't get access to the controls maintained on the page.
I have checked all this things before posting.
My methods are public and static and have the attributes Microsoft.Web.Script.Services.ScriptMethod and WebMethod.
They use only local variables and don't access any page controls.
I think that the error is different: PageMethods is undefined. I have this javascript error, so I don't think it's a problem with my methods. It's the PageMethods that is not defined.
If i define a simple method that return an integer, I have the same error. And I have the same error if i create a new ASP.NET AJAX Enabled web site project too.
hello again.
if i recall correctly, you just need to use the webmethod. here's a quick example i have here:
<%@. Page Language="C#" %>
<%@. Import namespace="LivroAtlas"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[System.Web.Services.WebMethod]
public static Aluno[] ObtemAlunos()
{
Aluno[] alunos = new Aluno[]{
new Aluno( "João", 15 ),
new Aluno( "Rita", 16 ),
};
return alunos;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="manager" />
<input type="button" value="invocar método da página" onclick="handle()" />
</form>
<script type="text/javascript">
function handle()
{
PageMethods.ObtemAlunos( handleCallback);
}
function handleCallback( res )
{
for( var i = 0; i < res.length; i++ )
{
alert( res[i].Nome + "-" + res[i].Idade );
}
}
</script>
</body>
</html>
btw, if you check the source of your page and don't see the global variable PageMethods, then that means that the ScriptManager is not injecting the proxy for the methods on the client side...
Finally I resolved the problem.
The solution is describe in this post from Shawn Burke's Blog. Due to a bug in this release of AJAX the page method must be in the same ASPX Page and not in codebehind.
Did you do anything to get the PageMethods object to appear on your page?
I've got public static void, I've got WebMethod and ScriptMethod, and I've got the function in the page rather than the code-behind... still nothing.
what the.......
okay... apparently closing the project, leaving it overnight, and changing absolutely nothing... fixed it... what do ya know. :p
This will break too much of my code...I think I will revert back to ATLAS until this is resolved/changed.
No comments:
Post a Comment