编写在"Test.Aspx.Cs"中的调用函数从JavaScript [英] Call Function Written In "Test.Aspx.Cs" From A Javascript

查看:119
本文介绍了编写在"Test.Aspx.Cs"中的调用函数从JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从test.aspx中的JavaScript调用用test.aspx.cs编写的函数?有可能吗?


在此先感谢

[Agent_Spock]
-添加了适当的标签
-更改了问题标题

how do i call a function written in test.aspx.cs from a javascript in test.aspx?? Is that possible?


Thanks in advance

[Agent_Spock]
- Added appropriate tag
- changed question header

推荐答案

是的,这是可能的

使在test.aspx.cs中编写的方法作为webmethod

Yes, That is possible

Make the methods written in test.aspx.cs as webmethod

[WebMethod(EnableSession = false)]
 public static string testfunction(string param)
 {
     return "abc";
 }



通过jquery ajax调用调用此函数



Call this function via jquery ajax call

function ajaxFunction() {


.ajax({ type: "POST", url: "test.aspx/testfunction", data: "{param: " + page + "}", contentType: "application/json", dataType: "json", success: function (msg) { OnSiteManagementSuccess(msg.d); }, error: function (msg) { msg.responseText; } }); }
.ajax({ type: "POST", url: "test.aspx/testfunction", data: "{param: " + page + "}", contentType: "application/json", dataType: "json", success: function (msg) { OnSiteManagementSuccess(msg.d); }, error: function (msg) { msg.responseText; } }); }



根据您的要求调用此ajax函数



call this ajax function as per your requiremnt




使用WebMethod的第一种方法: http://www.c-sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/ [
Hi,

First way using WebMethod : http://www.c-sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/[^]

To call a Control Event :

<input type="button" onclick="__doPostBack('[Your Control Unique ID','[Function Name]')" />


这篇关于编写在"Test.Aspx.Cs"中的调用函数从JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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