-
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>
- Set EnableViewstateMac="false" in target pages, as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" EnableViewStateMac="false" %>
- 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.
- 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>
- 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.