如何从客户端调用Asp .net服务器端方法(Javascript) [英] How to call Asp .net server side method from client(Javascript)

查看:74
本文介绍了如何从客户端调用Asp .net服务器端方法(Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我是Asp .net的新手.
谁能告诉我如何从客户端(Javascript)调用服务器端方法.
在此先感谢.

Hello All

I am new to Asp .net.
Can anyone tell me How to call the Server side method from client(Javascript).
thanks in advance.

推荐答案


只需将脚本管理器放在ur aspx页面中,并将enablePagemethods属性设置为true ...
在给你一个例子..
假设方法背后的代码是这样的


just place the script manager inside ur aspx page and enablePagemethods Property to true...
am giving you one example..
suppose the code behind method is like this

[WebMethod]
   public static string AddUser(string UserName)
{
..
body of the method
..
}



那么您可以像这样从ur javascript中调用该函数.
在javascript中..


PageMethods.AddUser(



then you can call the function from ur javascript like this..
inside the javascript ..


PageMethods.AddUser(


get(pageId +"txtUserName").value)


将此代码放入javascript函数中.然后在您需要的事件上触发此函数.
希望这对您有帮助
get(pageId + "txtUserName").value)


put this code inside a javascript function..and fire this function on which event you need..
Hope this may help you


从客户端调用服务器端功能使用页面方法的附加代码 [ ^ ]

一个简单的谷歌搜索将提供更多.
call Server Side function from Client Side Code using page methods[^]

A simple google search will give a lot more.


这篇关于如何从客户端调用Asp .net服务器端方法(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆