页面方法在 asp.net 中没有响应
我在页面方法的帮助下调用两个服务器端函数,但没有任何反应。 我在这里给出我的代码。所以请告诉我我犯了什么错误,
我的aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<a href="#" onclick="javascript:preview();">Test</a>
<br />
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSetvwState" runat="server" Text="Set Session Val" OnClientClick="SetSessionVal;return false;" />
<asp:Button ID="btnGetVwState" runat="server" Text="Get Session Val" OnClientClick="GetSessionVal;return false;"/>
<script language="javascript">
function preview() {
alert($get('TextBox1').value);
PageMethods.GetMessage("Hi", "Joy", onSuccess)
return false;
}
function onSuccess(res) {
alert(res);
}
function GetSessionVal() {
PageMethods.GetViewState(onSuccess)
return false;
}
function SetSessionVal() {
alert("pp");
PageMethods.SetViewState("Hi", "Tridip", onSuccess)
return false;
}
</script>
</form>
</body>
</html>
我的服务器端代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string GetMessage(string pr1,string pr2)
{
return pr1 + " " + pr2;
}
[System.Web.Services.WebMethod(EnableSession=true)]
public static void SetViewState()
{
HttpContext.Current.Session["data"] = "Hellp";
}
[System.Web.Services.WebMethod(EnableSession = true)]
public static string GetViewState()
{
return (String) HttpContext.Current.Session["data"] ;
}
}
}
请帮助我发现错误。谢谢
i am calling two server side function with the help of page method but nothing happen.
here i am giving my code. so please tell me what mistake i made,
my aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<a href="#" onclick="javascript:preview();">Test</a>
<br />
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSetvwState" runat="server" Text="Set Session Val" OnClientClick="SetSessionVal;return false;" />
<asp:Button ID="btnGetVwState" runat="server" Text="Get Session Val" OnClientClick="GetSessionVal;return false;"/>
<script language="javascript">
function preview() {
alert($get('TextBox1').value);
PageMethods.GetMessage("Hi", "Joy", onSuccess)
return false;
}
function onSuccess(res) {
alert(res);
}
function GetSessionVal() {
PageMethods.GetViewState(onSuccess)
return false;
}
function SetSessionVal() {
alert("pp");
PageMethods.SetViewState("Hi", "Tridip", onSuccess)
return false;
}
</script>
</form>
</body>
</html>
my server side code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string GetMessage(string pr1,string pr2)
{
return pr1 + " " + pr2;
}
[System.Web.Services.WebMethod(EnableSession=true)]
public static void SetViewState()
{
HttpContext.Current.Session["data"] = "Hellp";
}
[System.Web.Services.WebMethod(EnableSession = true)]
public static string GetViewState()
{
return (String) HttpContext.Current.Session["data"] ;
}
}
}
please help me to catch the mistake. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里缺少
()
(SetSessionVal
、GetSessionVal
):missing
()
here (SetSessionVal
,GetSessionVal
):