Calling serverside function from Javascript

3 views
Skip to first unread message

Vinay

unread,
Nov 6, 2009, 6:09:09 AM11/6/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hi there,

I m trying to call server side function from javascript in asp.net.
Right now i m trying a simple example..but i m unable to do it. hope u
can help in that.

Body Code:
=======================

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true">
</asp:ScriptManager>
<script language="javascript" type="text/javascript">
function CallSum()
{
PageMethods.say("Hello World!!!");
}
</script>

<div>
<asp:Button ID="btn" runat="server" OnClientClick="CallSum()"
Text="Show" />
</div>
</form>
</body>
</html>
=====================

Serverside Code

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;


public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

[System.Web.Services.WebMethod]
public void go(string message)
{
Response.Write("<script>alert('"+message+"');</script>");

}
}

=============================================
The above code not showing a message box on button click.

Thanks in advance..

Vinay

Felipe Teixeira

unread,
Nov 6, 2009, 11:36:25 AM11/6/09
to dotnetde...@googlegroups.com
Hello there Vinay,

Look, I've seeing a lot of implementations like the one you are trying to build up, but if you really need some good implementation for AJAX using ASP.Net, I'd suggest you to dig into both IHttpHandlerFactory and IHttpHandler interfaces... forget about this Page Methods implementation cuz it does sucks.

Good luck!

Felipe Teixeira
Microsoft Certified Technology Specialist - MCTS - Microsoft .Net Framework 2.0
Application Development Foundation MS
Web -based Client Development
Mobile: +55 (11) 8021-6457
txdo...@googlewave.com
http://iguessimnotcrazy.wordpress.com/



2009/11/6 Vinay <getvin...@gmail.com>
Reply all
Reply to author
Forward
0 new messages