从脚本函数调用服务器方法 [英] Calling a server method from script function
本文介绍了从脚本函数调用服务器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从java脚本函数调用服务器方法,但它正在调用。那它有什么问题。请告诉我。
这是脚本:
Hi,
I am calling a server method from a java script function but it is getting invoke. So what is the problem it is having. Please advise me.
This is the script:
<script type="text/javascript" language="javascript">
function servermethod() {
var name = $get("txtname").value;
PageMethods.CallingserverMethod(name);
alert(name);
}
Code Behind:
Code Behind:
[WebMethod]
public static string CallingserverMethod(string name)
{
return "Hi" + name + Environment.NewLine + "This is an example";
}
推荐答案
get(txtname)。value;
PageMethods.CallingserverMethod(name);
alert(姓名);
}
get("txtname").value; PageMethods.CallingserverMethod(name); alert(name); }
Code Behind:
Code Behind:
[WebMethod]
public static string CallingserverMethod(string name)
{
return "Hi" + name + Environment.NewLine + "This is an example";
}
.cs file
[ScriptMethod, WebMethod]
public static string CallingserverMethod(string name)
{
return "Hi" + name + Environment.NewLine + "This is an example";
}
.aspx file
<script type="text/javascript">
function servermethod()
{
PageMethods.CallingserverMethod(onSuccess, onFailure);
}
function onSuccess(result) {
alert(result);
}
function onFailure(error) {
alert(error);
}
</script>
然后点击此处调用此servermethod() .aspx代码中的按钮。
Then call this servermethod() on click of button in your .aspx code.
这篇关于从脚本函数调用服务器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文