javascript中调用后台的方法,就是实现无刷新改变文本框中的值。首先要前台页面中 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>加入EnablePageMethods="true",
同时,在后台定义方法时如下:
[System.Web.Services.WebMethod]
public static string Foo(string name)
{
return "hello";
}
页面如下:
<script language="javascript">
function win() {
PageMethods.Foo("aa", myResult, funError);//"aa"为Foo方法中的参数值
}
function myResult(temp) {
document.getElementById("txt1").value = temp;
}
function funError(err) {
alert("Error:" + err._message);
}
</script>
<input id="Button1" type="button" value="button" onclick="win()" />
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
本文介绍如何使用ASP.NET AJAX技术实现网页上的文本框值的无刷新更新。通过在后台定义WebMethod方法并在前端JavaScript中调用,可以实现在不重新加载整个页面的情况下更新特定元素的内容。
480

被折叠的 条评论
为什么被折叠?



