One MAJOR difference between AJAX.NET and Atlas.NET seems to be that AJAX.NET is able to expose methods in your codebehind to the client.
Why doesn't Atlas do this? Or am I mistaken?
With AJAX.NET it's just a simple line or two:
Ajax.Utility.RegisterTypeForAjax(GetType(myClass))
<Ajax.AjaxMethod()>Public Function myFunction
PLEASE tell me Atlas has something comparable to this. I don't have the time to rewrite all my code-behind methods in javascript or atlas script.
![]() |
0 |
![]() |
All you need to do in Atlas to expose a method on your page (or its code behind class) is to put a [WebMethod] attribute on it. See here for an example.
David
![]() |
0 |
![]() |
well, i did try that. but it didn't work. i dont know if it needs to specify the namespace in the code-behind or in the aspx page, but i can't the javascript to work.
here's my codebehind ...
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Services; public partial class sendersearch : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public string Login(string user, string pass) { return "success"; } }
and here's my aspx page...
"C#" AutoEventWireup="true" CodeFile="sendersearch.aspx.cs" Inherits="sendersearch" %> <head id="Head1" runat="server"> <atlas:ScriptManager runat="server" ID="scriptManager" EnableScriptComponents="true"> <services> <atlas:servicereference path="sendersearch.aspx.cs" /> </services> </atlas:ScriptManager><script type="text/javascript"> function DoLogin(){ sendersearch.Login('',''); //sendersearch is the name of the page (and the class in the code-behind) } </script> </head> <body> <form id="Form1" action="" runat="server">
<div> <input type="button" value="Login" onclick="DoLogin()" /> <br /> </div> </form> </body>
</html>
![]() |
0 |
![]() |
forget it. i found out what it was.
you've got to use a keyword when referring to the method in the code behind (or in a page method). the keyword is 'PageMethod'. duh.
for example....
PageMethod.DoLogin('','');
![]() |
0 |
![]() |
Correct. Also, you don't need your atlas:servicereference tag, as PageMethods are automatically available.
David
![]() |
0 |
![]() |
I've tried to get a variation of this to work in vb -- could you tell what I'm doing wrong:
Here's my .aspx file:
<%
@ Page Language="VB" AutoEventWireup="false" CodeFile="AtlasScriptWithCodebehind.aspx.vb" Inherits="AtlasScriptWithCodebehind" %><!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <atlas:ScriptManager runat="server" EnableScriptComponents="true" ID="scriptManager"> </atlas:ScriptManager> <script type="text/javascript"> function DoSearch(){
var QuantityElem = document.getElementById("quantity"); var ProductIDElem = document.getElementById("productID");AtlasScriptWithCodebehind.PageMethod.HelloWorld(ProductIDElem.value, QuantityElem.value, OnRequestComplete);
}
function OnRequestComplete(result){
var RsltElem = document.getElementById("Results");RsltElem.innerHTML = result;
}
</script> <style type="text/css"> body { font: 11pt Trebuchet MS; font-color: #000000; padding-top: 72px; text-align: center } .text { font: 8pt Trebuchet MS } </style> </head> <body> <form id="Form1" runat="server"> <div>Add to Cart
<input id="productID" type="text" /> <input id="quantity" type="text" /> <input id="SearchButton" type="button" value="Search" onclick="DoSearch()" /> </div> </form> <hr style="width: 300px" /> <div> <span id="Results"></span> </div> </body></
html>Here's my codebehind:
Imports
SystemImports
System.DataImports
System.ConfigurationImports
System.CollectionsImports
System.WebImports
System.Web.SecurityImports
System.Web.UIImports
System.Web.UI.WebControlsImports
System.Web.UI.WebControls.WebPartsImports
System.Web.UI.HtmlControlsImports
System.Web.ServicesPartial
Public Class AtlasScriptWithCodebehind Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub<WebMethod()> _
Public Function HelloWorld(ByVal productID As String, ByVal quantity As String) As Stringquantity = Server.HtmlEncode(quantity)
productID = Server.HtmlEncode(productID)
If Not String.IsNullOrEmpty(quantity) Then Return String.Format("Hello, your productID is {0} and your quantity input is {1}. The " _&
"current time is {2}", productID, quantity, DateTime.Now) Else Return "The query string was null or empty" End If End Function
End
ClassI keep getting a javascript error on the page:
'AtlasScriptCodeBehind' is undefined.
Thank you so much.
![]() |
0 |
![]() |
Ignore my last post -- the keyword in the javascript call should be PageMethods.HelloWorld not PageMethod.HelloWorld.
![]() |
0 |
![]() |