PageMethods is undefined

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/1/2009 2:23:53 PM
Gravatar
Total Posts 10

PageMethods is undefined

I am getting an error: "Microsoft JScript runtime error: 'PageMethods' is undefined" withing a custom module.
I already made sure that enablePagemethods on layout.master is set to true.
The ajax library inside bin folder is AjaxControlToolkit.dll is 1228kb and it seems to be the one which was shipped with the Mojo instalation. Is there anything I need to do to get problem resolved?
 

PS: I have other applications which require enabling page methods and they are working fine.

Rod

7/1/2009 9:40:07 PM
Gravatar
Total Posts 10

Re: PageMethods is undefined

Just providing a little bit more of info.

I did a quick test placing a static aspx and I checked PageMethods worked with no problem. In fact when I view the source code I can see its initialization;

var PageMethods = function() {
PageMethods.initializeBase(this);

Now when I do the same thing within a module (ascx) page I don't see the initialization like above. What else can I do?

Thanks

 

7/2/2009 6:02:08 AM
Gravatar
Total Posts 18439

Re: PageMethods is undefined

Hi,

First thing to understand is that <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" /> declared in the layout.master is not part of the ajaxtoolkit at all, its part of the core MS AJAX framework in the System.Web.Extensions namespace. In 2.0 .NET this was shipped as a separate dll but in 3.5 its built in and no extra dll is needed.

The ajaxtoolkit does have a script manager that can be used instead of the normal script manager, I do not know whether using it would solve the problem for you.

You don't mention what version of mojoPortal you are using. There was an early version of MS Ajax that had a script manager that did not support page methods, so it makes me wonder what version of .NET you are using.

Hope it helps,

Joe

 

7/2/2009 7:34:34 AM
Gravatar
Total Posts 10

Re: PageMethods is undefined

Joe, thanks for clarifying the ajax extension. The version is that I am using is mojoportal-2-3-0-8 with framework 3.5.
On windows\assembly I see these two entries for System.Web.Extensions:
Assembly Name                Version
System.Web.Extensions    3.5.0.0
System.Web.Extensions    1.0.61231.0

I think this version supports PageMethods because otherwise the test that I did would not work. It seems to be an issue between the module and the master page layout that is not letting PageMethods library instantiate. I was thinking about removing scriptmanager programatically and add it only within the module scope but asp.net will throw an error, besides Mojo requires it too so it is not a good option.

7/2/2009 7:43:38 AM
Gravatar
Total Posts 18439

Re: PageMethods is undefined

I would make sure your custom module is referencing the 3.5 version of System.Web.Extensions and if possible uninstall the older 1.0 version from the machine just to make sure. 

If that doesn't solve it then please tell more about what you are doing inside your module.

Hope it helps,

Joe

7/2/2009 10:10:40 AM
Gravatar
Total Posts 10

Re: PageMethods is undefined

Joe, I just did a fresh installation on another machine and still the problem persists. It seems like the scripmanager is not hooked to the module, although I can access it via findcontrol it is not rendering properly:
ScriptManager scriptController;
scriptController = (ScriptManager)Page.Master.FindControl("ScriptManager1");

This is the sample code of my module:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Login.ascx.cs" Inherits="Modules_ImovelAjato_Login" %>
<%@ Import Namespace="System.Web.Services" %>
<script language="C#" runat="server">
[WebMethod] // Register javascript method
public static bool VerifyLogin(string Email, string Password)
{
// Just returning something to test
return true;
}
</script>

<script type="text/javascript">

function VerifyLoginViaAjax() {
PageMethods.VerifyLogin("blabla@blabla.com", "blabla", onSucceeded, onFailed);
}
function onSucceeded(result, userContext, methodName) {
alert(result);
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("<%=LinkButton1.ClientID %>", "", false, "", "http://www.joiaimoveis.com/admin/Login.aspx", false, true));
}

function onFailed(error, userContext, methodName) {
alert("An error occurred")
}

</script>

<input id="Button1" type="button" value="Post via Ajax" onclick="VerifyLoginViaAjax();" />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="http://www.joiaimoveis.com/admin/Login.aspx" Style="display: none">LinkButton</asp:LinkButton>
 

7/3/2009 9:23:56 AM
Gravatar
Total Posts 18439

Re: PageMethods is undefined

When I google this error I see it is a common error when trying top use pagemthods from master pages or usercontrols, it seems that PageMethods really means "PageMethods" as in you can only use them from a page not a usercontrol. I think the reason is because there is an autogenerated proxy for calling the webmethod and this proxy can only point to a page not a usercontrol, and the UserControl does not know what page it may be on. Maybe some workaround is possible if you were to edit the generated proxy code and hard code the real page url, but even if it works it seems a bad way to go. You can make a web service call more easily.

This article had relevant info:

http://www.west-wind.com/weblog/posts/152493.aspx

Hope it helps,

Joe

7/3/2009 10:12:29 AM
Gravatar
Total Posts 10

Re: PageMethods is undefined

Thanks, I kind of had that feeling and I am already changing my approach. However, isn't dangerous to expose ajax calls via webservices. For instance lets say you have method called LoginAuthorization which has 2 parameters email and password. Someone could easily call this public method and use brute force to hack into the system. Of course I would not let it happen and I would check the number of attempts, just to give an idea of security issues for switching to web services.

Rod

7/3/2009 10:21:20 AM
Gravatar
Total Posts 18439

Re: PageMethods is undefined

That seems no different than the publicly exposed login page. Using the memberhship provider and site settings we can lockout an account if there are more than x failed password attempts within a window of y time. So whatever policy is enforced in the login page should be enforced in any login web service. So the login page uses the membershipprovider and as long as the web service also does then the policy will be enforced consistently in either case.

Hope it helps,

Joe

7/3/2009 11:05:58 AM
Gravatar
Total Posts 10

Re: PageMethods is undefined

Good point.

Just in case I am posting my solution. It is not the most elegant but it does not require PageMethods. I use hiddenfields to read data from ajax postback.

Good point.

Just in case I am posting my solution. It is not the most elegant but it does not require PageMethods. I use hiddenfields to read data from ajax postback.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Login.ascx.cs" Inherits="Modules_Iml_Login" %>
<%@ Import Namespace="System.Web.Services" %>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
prm.add_beginRequest(beginRequest);

var postBackElement;
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack()) {
args.set_cancel(true);
}
postBackElement = args.get_postBackElement();
}

function beginRequest(sender, args) {
$get('LoadingDiv').style.display = 'block';
}

function EndRequest(sender, args) {
if (postBackElement.id == '<%=btSubmit.ClientID %>') {
var authkey = $get('<%=FrmAuthKey.ClientID %>');
if (authkey.value != "key is NULL") {
var Domain = $get('<%=FrmDomain.ClientID %>');
if (Domain != null) {
$get('LoadingText').innerHTML = 'Loading site, please wait...';
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("<%=LinkButton1.ClientID %>", "", false, "", "http://" + Domain.value + "/admin/Login.aspx", false, true));
}
} else {
$get('LoadingDiv').style.display = 'none';
alert('Email ou password Inválidos!');
}
}
}

</script>
<!--Begin Login Info-->

<div style="text-align: center; margin: 0 auto; width: 500px">
<div class="FormRow">
<div class="left">&nbsp;</div>
<div class="left">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Data/Sites/1/ImovelAjato/admin_icon.jpg" />
</div>
</div>
<div class="FormRow">
<div class="left" style="width: 100px"> <b>Email:</b></div>
<div class="left">
<asp:TextBox ID="FrmEmail" runat="server"></asp:TextBox>
</div>
</div>
<div class="FormRow">
<div class="left" style="width: 100px"> <b>password</b>:</div>
<div class="left">
<asp:TextBox ID="FrmPassword" runat="server" TextMode="Password"></asp:TextBox>
</div>
</div>
</div>
<!--End Login Info-->
<!--Begin Update Panel-->
<div style="text-align: center; margin: 0 auto; width: 500px">
<asp:UpdatePanel ID="UpdatePanelSubmit" runat="server">
<ContentTemplate>
<div class="FormRow">
<div class="left" style="width: 100px">&nbsp;</div>
<div class="left">&nbsp;
<asp:Button ID="btSubmit" runat="server" OnClick="btSubmit_Click" Text="Acessar" />
<asp:HiddenField ID="FrmDomain" runat="server" />
<asp:HiddenField ID="FrmAuthKey" runat="server" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<!--End Update Panel-->
<div class="FormRow" style="margin-top: 10px">
<div class="left" style="width: 100px">&nbsp;</div>
<div class="left">
<div id="LoadingDiv" style="display:none; height:50px; text-align:left"><img src="Data/Sites/1/ImovelAjato/loading2.gif" /><br />
<label id="LoadingText">Authenticating ...</label>
</div>
</div>
</div>
<%-- <div class="FormRow" style="height: 50px"> </div>
--%> <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="http://www.joiaimoveis.com/admin/Login.aspx" Style="display: none">LinkButton</asp:LinkButton>
</div>

 

You must sign in to post in the forums. This thread is closed to new posts.