Calling serverside function from Javascript

Calling serverside function from Javascript

Post by Vina » Sat, 07 Nov 2009 20:09:09



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!!!");

Quote:}

</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>");

    }

Quote:}

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

Thanks in advance..

Vinay

 
 
 

Calling serverside function from Javascript

Post by Felipe Teixeir » Sun, 08 Nov 2009 01:36:25


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
<http://msdn.microsoft.com/en-us/library/system.web.ihttphandlerfactor...>and
IHttpHandler
<http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx>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

http://iguessimnotcrazy.wordpress.com/


Quote:

> 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


 
 
 

1. I want to call a javascript function WITH parameters function from c#

I want to call a javascript function WITH parameters function from c#
code; I already did this:
....
StartDate.Attributes.Add("onTextChange","DateGreaterThan(" +
StartDate.Value + "," + RequiredByDate.Value + ");");
....
in the control (C# code)

What is the syntax to call the function from asp.net?
this does not work:
<combo:WebDateChooser id="StartDate" runat="server"
onValueChange="DateGreaterThan(Date2, Date1);"></combo:WebDateChooser>

this is the function in javascript:

function DateGreaterThan(Date2,Date1)
{ ....}

2. Dimension Settings

3. calling a javascript function from a vb function

4. AIX Frequently Asked Questions (Part 3 of 5)

5. Calling a javascript function from code behind

6. Please answer to me...

7. How to call JavaSCRIPT Function in axWebBrowser?

8. How to stop the URLReferrer from changing?

9. Can JavaScript call c++ functions defined in an MFC-based browser app?

10. Call javascript function onload event of usercontrol

11. calling a javascript function from asp code

12. calling code behind function from javascript

13. call javascript function after xmlhttp (ajax)