开发者

Page Method not responsing in asp.net

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


missing () here (SetSessionVal, GetSessionVal):

 <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;"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜