FAQ

This FAQ is work in progress. More information will come soon, to let you know how to use custom objects as parameters (see the samples in the meantime) or even how to stop using PageMethods...

When I install PageMethods, I get the following error: The file "C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\PageMethods.Addin" already exists.
What is this? What can I do?
This was a known problem with the installer. It has been fixed in the latest releases.
When you were re-installing PageMethods, the install was choking on a file that was not removed automatically from a previous installation. Please use the latest version.
After installing PageMethods, the PageMethods Add-in does not appear in "Tools | Add-in Manager...". Is there something wrong with the installer or my configuration?
If you have Windows with a culture other than English, you may have trouble with Visual Studio 2005 add-ins. Under "Tools | Options | Environment | Add-in/Macros Security", you'll see a list of file paths for add-ins, but for example on some German computers, you'll have to add "%ALLUSERSPROFILE%\Anwendungsdaten\Microsoft\MSEnvShared\Addins" in addition to "%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\Addins". I guess the same kind of problem can happen with other cultures. Make sure the right paths are added to this list.
Alternatively, you can also copy the .addin file to "%APPDATA%\Microsoft\MSEnvShared\Addins".

If this does not work, you can register the add-in using the PageMethodsAddinVS2005.reg file, which is in the installation folder ("C:\Program Files\metaSapiens\PageMethods for VS 2005" by default).
I think I have done everything right, but when I try to reference my page methods using the MyPageMethods namespace, nothing comes up in intellisense and when I compile my project I receive the error "The name 'MyPageMethods' does not exist in the current context". What could be wrong?
To track down what the problem may be, please go through the following checklist:

  • Have you tried to go through the steps described in the tutorial?
  • Did you check that the PageMethods add-in is activated in the Add-in Manager?
  • Is the PageMethodsEnabled property of the project set to "true"?
  • When you compile the project, is a PageList.xml file generated in the application directory (Visual Studio 2005's Web Application model or VS 2003) or in the App_Code directory (Visual Studio 2005's Web Site model)?
  • If you use the Web Site model with Visual Studio 2005, did you register the PageMethods build provider in the web.config file?
If it still doesn't work, you can contact the support with a detailed description of your situation and answers to the following questions:

  • Are you using Visual Studio 2003 or 2005?
  • Which version of PageMethods are you using? (look in "Tools | PageMethods" please)
  • Is your project in C# or in VB.NET?
You may also send us a copy of your project so we can reproduce the issue and help you spot the problem.
Can web applications using PageMethods be built from the command line?
Several options are available:

  • You can use aspnet_compiler.exe to compile your ASP.NET web applications. Note that this will work only if you have built the site (interactively) with Visual Studio before and the PageList.xml file has been generated. This is not a problem: the PageList.xml file is part of your project and should be copied onto your build server with the rest of the source code.
  • Alternatively, you can use the Web Application model (recommended), deactivate the PageMethods add-in for the command line mode (see the "Tools | Add-in Manager..." menu), and build with Visual Studio's command line mode (devenv.com /Build).
    This solution also requires the PageList.xml file to be generated before using the command line mode.
    Note that PageMethods needs to be installed on the build server in this case.
  • Another solution, which doesn't require to have the PageList.xml file before-hand, is to use Visual Studio's command line mode. Just call "devenv.com /Build" after making sure that "Command Line" is checked for the PageMethods Add-in "Tools | Add-in Manager...".
    Be warned that unfortunately Visual Studio is not stable in this context, so it works, unless VS decides otherwise! Give it a second or third try, VS may not always crash...
Can I use method overloading with PageMethods? I get an exception when I have two page methods with the same name.
Method overloads are not currently supported by PageMethods. Support for this may be added in a future version, but for the moment you cannot have to page methods with the same name in one page.
You have to give your methods different names like "DisplayDefault" and "DisplayAdvanced".
I have this page with page methods, can I refer to it without any parameter on the URL? Is the PageMethod parameter mandatory in URLs?
PageMethods uses a parameter in the URL to know which page method to invoke, so you need at least the PageMethod parameter in your URLs. However, PageMethods lets you define one default page method per page. If you use a default page method, the name of this method does not need to be in the URL. This means you can have URLs like MyPage.aspx?Parameter1=1&Parameter2=2 or simply MyPage.aspx instead of MyPage.aspx?PageMethod=MyMethod&Parameter1=1&Parameter2=2 and MyPage.aspx?PageMethod=MyMethod.

To declare a default page method, you tag it with the PageMethod attribute with true as an argument: [PageMethod(true)] in C#, <PageMethod(True)> in VB.NET.
To have default page methods invoked, you can either:
  1. have your page inherit from MetaSapiens.PageMethods.BasePage and add a constructor like this to your page class:
    public YourPage() : base(true) { }
  2. or you can add the following code to Page_Load:
    if (!IsPostBack) PageMethodsEngine.InvokeMethod(this, true);
To help you understand how this works, here is the code that is executed automatically by MetaSapiens.PageMethods.BasePage during Load:
if (!IsPostBack)
      if (!PageMethodsEngine.InvokeMethod(this, _HandleDefaultMethod))
        throw new PageMethodsException("Bad web page invocation. Check the URL parameters.");
I get a MethodAccessException exception ("Attempt to access the method failed") when trying to access to my pages. What is this? What should I do?
This exception occurs when ASP.NET applications run under partial trust. This typically happens in shared hosting environments. To avoid this problem, declare your page methods as "public", instead of "private" or "protected". You can get more details in this blog post.
Does PageMethods support HTTP POST?
In order to use HTTP POST with PageMethods, you need to do the following:

  1. Use the PageMethods HTTP module by adding the following code to Web.config in system.web:
    <httpModules>
      <add name="PageMethodsModule" type="MetaSapiens.PageMethods.PageMethodsModule, PageMethods"/>
    </httpModules>
    	    
  2. Set EnableViewstateMac="false" in target pages, as follows:
    
        <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" EnableViewStateMac="false" %>
    	    
  3. In order to use HTTP POST with hyperlinks, use the xxx_Post methods:
    
        HyperLink1.NavigateUrl = MyPageMethods.Page1.Method1_Post(12, HyperLink1);
    Make sure to pass the HyperLink control as the last argument.
  4. In order to invoke a page method from a web page that is not an ASP.NET page, you need to set the form's action to the ASPX where the page method is in and use a hidden field named PageMethods_Data as follows:
    <html>
      <body>
        <form action="Page1.aspx" method="post">
          <input type="hidden" name="PageMethods_Data" value="?PageMethod=Method1&i=12" />
          <input type="submit" value="Invoke page method Method1 with i = 12" />
        </form>
      </body>
    </html>
    Starting with PageMethods 1.6, the value for the hidden field can be obtained using a call like:
    MyPageMethods.Page1.GetPostData(12);
    Optionally, each parameter can be provided separately. e.g.:
    <html>
      <body>
        <form action="Page1.aspx?Param1=aaa" method="post">
          <input type="hidden" name="PageMethod" value="Method1" />
          <input type="text" name="Param2" value="bbb" />
          <input type="submit" value="Invoke page method Method1 with Param1 = aaa and Param2 = bbb" />
        </form>
      </body>
    </html>
  5. In order to use PageMethods with a Button, you can use the following code:
    Button1.OnClientClick = "javascript:document.location = '"+MyPageMethods.Page1.Method1_Post(12, Button1)+"'";
    Starting with PageMethods 1.6, it is also possible to use the following code:
    Button1.PostBackUrl = MyPageMethods.Page1.TildePageUrl;
        PageMethods_Data.Value = MyPageMethods.Page1.GetPostData(12);
    where PageMethods_Data is a HiddenField.
    You can also provide the parameters separately, as demonstrated in the previous option.
How can I use URL rewriting with PageMethods? Is there built-in support for this?
URL rewriting allows you to use URLs like http://myserver/App1/Customer12.aspx instead of http://myserver/App1/Pages/FrmCustomer.aspx?PageMethod=EditCustomer&CustomerID=12. The basic steps to use URL rewriting are:

  1. use the UrlFormat attribute on your page methods (this is demonstrated at the end of the tutorial).
  2. implement the rewriting mechanism in Global.asax or in a HTTP Module.
    The demos provide some code that shows this in the Global.asax file (Global.asax.cs/Global.asax.vb if you use Visual Studio 2003).
For the moment you have to use your own URL rewriting code. You can get an engine here for example: http://www.urlrewriting.net

When using URL rewriting and POST at the same time you may notice that URLs get reverted to their real value instead of their rewritten value. In order to avoid this, you have to implement one of the solutions described here or at the bottom of this page (See "Handling ASP.NET PostBacks with URL Rewriting").

Future versions of PageMethods may come with a built-in URL rewriting engine.
Is PageMethods free? What is the licensing scheme?
PageMethods is completely free of charge, and will remain so. You can find the complete license here.
PageMethods consists of an add-in (PageMethods.Addin.dll) and a class library (PageMethods.dll).
The add-in is used within Visual Studio at design-time, the class library is used at run-time. Both are free of charge. The class library is royalty-free and deployed with your applications.
Can PageMethods be used with Visual Web Developer, Visual Studio Express editions?
PageMethods works as a Visual Studio add-in. Since there is no support for add-ins in the Express editions, as can be seen in the Visual Studio editions comparison table, PageMethods cannot be used with Visual Web Developer 2005 Express.
 
Web metaSapiens.com
Part of the metaSapiens network: metaSapiens | .NET and Java Jobs | Fabrice's weblog | SharpToolbox | JavaToolbox | Tuneo | LINQ in Action | MapShares | Clair de Bulle
transatlantys
Managed Windows Shared Hosting by OrcsWeb