I'm trying to access a server side method from a client side one (that is just calling a server method from javascript). I'm using .NET 4.0 Visual Studio 2010 Ultimate. I'm building a web control (ascx). I have an ascx page (the control's html) and an ascx.cs page: The ascx is the following:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="BoxButton.ascx.cs" Inherits="ATB.Controls._BoxButton" %>
<asp:ScriptManager ID="SM_ScriptManager" runat="server" EnablePageMethods="true" />
<script type="text/javascript">
function handle() {
PageMethods.manageHandler();
}
</script>
<span id="BoxButton_HtmlSpan" runat="server" onclick="handle();" style="background-color:#efefef;border-style:solid;border-width:1px;border-color:#cccccc;height:25px;text-align:center;padding:3px 3px 3px 3px;font-family:Arial, Helvetica, sans-serif;font-size:12px;font-style:normal;color:#333333;line-height:15px">
<asp:Label runat="server" Text="Button" id="Text_Label"></asp:Label>
</span>
And the ascx.cs file is this one (just printing the function):
[System.Web.Services.WebMethod]
public static string manageHandler() {
int i = 0;
System.Console.WriteLine("Ciao");
return "Hello";
}
Well, as you can see I'm trying to solve my problem through pagemethods, well it does not work and I always getPageMethods is undefined b y the JScript runtime manager. Well, is it possible that PageMethods are not available in .net 4.0?
Anyway, is there another approach for solving the problem regarding server side method calling from client side scripts? I understood that pagemethods are nothing more than a web service, and this bothers me a little when thinking about security in my web app.