API Questions on Kentico API.
Version 5.x > API > Please, how to use PageMethods in kentico CMS???? View modes: 
User avatar
Member
Member
daothanhson-gmail - 6/29/2012 1:10:48 PM
   
Please, how to use PageMethods in kentico CMS????
I'm try use PageMethod in BlankAspx template. But I don't successful.

I was set EnablePageMethods="true".
<asp:PlaceHolder runat="server" ID="plcManagers">
<asp:ScriptManager ID="manScript" runat="server" EnablePageMethods="true" />
<cms:CMSPageManager ID="CMSPageManager1" runat="server" />
</asp:PlaceHolder>

And write a code javascript:
<script type="text/javascript">

function OnSuccess(result) {
window.location = "/manage/permission.aspx";
return false;
}

function OnError(error) {
HidePanel('tbPer');
ShowPanel('error-msg');
}

function AddPermissionForRole(strRoleName, intPermissionId, chkId) {
PageMethods.CheckPermission(strUserName, intPermissionId, OnSuccess,OnError);
}
</script>

and code behind function
[WebMethod(EnableSession = true)]
public static bool CheckPermission(string username, string permissionId)
{
return true;
}

But I don't use PageMethod? Allway return error object [Object] in OnError javascript function.
Please......help me...

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/1/2012 3:49:10 PM
   
RE:Please, how to use PageMethods in kentico CMS????
Hi,

Please find attached portal template example which calls webservice method. The working code is in comments.
<%@ Page Language="C#" AutoEventWireup="true" Inherits="CMSPages_PortalTemplate"
ValidateRequest="false" MaintainScrollPositionOnPostback="true" EnableEventValidation="false"
CodeFile="PortalTemplate.aspx.cs" %>

<%=DocType%>
<html xmlns="http://www.w3.org/1999/xhtml" <%=XmlNamespace%>>
<head id="head" runat="server" enableviewstate="false">
<title id="_title" runat="server">My site</title>
<asp:Literal runat="server" ID="tags" EnableViewState="false" />

<%-- <script language="javascript" type="text/javascript">

function SubmitData() {

PageMethods.GetData();
}

</script>--%>

</head>
<body class="<%=BodyClass%>" <%=BodyParameters%>>
<form id="form" runat="server">
<asp:PlaceHolder runat="server" ID="plcManagers">
<ajaxToolkit:ToolkitScriptManager ID="manScript" runat="server" ScriptMode="Release"
EnableViewState="false" EnablePageMethods="true" />
<cms:CMSPortalManager ID="manPortal" ShortID="m" runat="server" EnableViewState="false" />
</asp:PlaceHolder>
<cms:CMSPagePlaceholder ID="plcRoot" ShortID="p" runat="server" Root="true" />
<asp:PlaceHolder runat="server" ID="plcFooter"></asp:PlaceHolder>
<%-- <asp:Button ID="Button1" runat="server" Text="Call Page Methods"
OnClientClick="return SubmitData()"/>--%>
</form>
</body>
</html>

using System;

using CMS.UIControls;
using System.Web.Services;

public partial class CMSPages_PortalTemplate : PortalPage
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

// Init the header tags
tags.Text = HeaderTags;
}

//[WebMethod]
//public static void GetData()
//{
// throw new Exception("Custom Error :) ");
//}
}

Best regards,
Ivana Tomanickova

User avatar
Member
Member
daothanhson-gmail - 7/6/2012 1:17:39 PM
   
RE:Please, how to use PageMethods in kentico CMS????
Thanks kentico_ivanat

But I use Blank Aspx Template. Can you help me??...

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/11/2012 11:31:52 AM
   
RE:Please, how to use PageMethods in kentico CMS????
Hi,

have you tried to add the code to your aspx template?

The script part could be the same. If you tried and it was not working, what kind of error did you receive?

Thank you for clarification.

Best regards,
Ivana Tomanickova

User avatar
Guest
vinay - 7/11/2013 10:36:41 AM
   
RE:Please, how to use PageMethods in kentico CMS????
[WebMethod]
[ScriptMethod]
public static bool SendInvite(int ID)
{
try
{
ImpactWorks.FBGraph.Connector.Facebook facebook = new ImpactWorks.FBGraph.Connector.Facebook();

IFeedPost post = new FeedPost();
post.Action = new FBAction { Link = "http://blog.impact-works.com/", Name = "Read" };
post.Caption = "Inviting you to read a blog post";
post.Description = "Hey, Come visit our blog!!!";
post.Message = "Blog Invite";
post.Name = "Blog Invite";
post.Url = "http://blog.impact-works.com/";
var postID = facebook.PostToWall(ValidationHelper.GetInteger(ID, 0), post);

return true;
}
catch
{
return false;
}
}

aboveb is my webmethod
and i am calling from ajax using following code but it shows error Unknown webmethod
$(function () {
//Binding click for Invite links by finding via data-id
$("a[data-id]").click(function () {
alert('d');
//Get the FBID
var id = $(this).attr("data-id");
//AJAX request
//var uri = "~/imuse_Webservices/Imuse_CommonSerivce.asmx/SendInvite";
var uri = "~/InviteFriendsToJoinImuse.aspx/SendInvite";
//Pointer to our anchor
var anchor = $(this);
$.ajax({
data: "{ID:" + id + "}",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: uri,
success: function (result) {
if (result.d) {
//Change the anchor text to INVITED
anchor.html("Invited");
//Unbind the previous click
anchor.unbind("click").click(function () {
alert("Already Invited!!");
});
}
},
error: function (xhr, status) {
alert(status + " - " + xhr.responseText);
}
});
});
});

User avatar
Guest
Salah Thabet - 7/23/2013 4:42:59 PM
   
RE:Please, how to use PageMethods in kentico CMS????
I have the same problem.