zoukankan      html  css  js  c++  java
  • ScriptManager之EnablePageMethods属性(转)

    ScriptManager的EnablePageMethods属性用于设定客户端javascript直接调用服务端静态WebMethod

    EnablePageMethods.aspx

    <script type="text/javascript">
            var txtName;
            var lblMsg;
            function pageLoad(){
                txtName=new Sys.Preview.UI.TextBox($get('txtName'));
                lblMsg=new Sys.Preview.UI.Label($get('lblMsg'));
            }
            function sayHello(){
                PageMethods.SayHello(txtName.get_text(),cb_SayHello);
            }
            function cb_SayHello(result){
                lblMsg.set_text(result);
            }
        </script>

    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
            <Scripts>
                <asp:ScriptReference Name="PreviewScript.js" Assembly="Microsoft.Web.Preview" />
            </Scripts>
            </asp:ScriptManager>
            <input type="text" id="txtName" />
            <input type="button" value="invoke" onclick="sayHello()" />
            <div id="lblMsg"></div>
        </div>
        </form>

     

    EnablePageMethods.aspx.cs

    [System.Web.Services.WebMethod]
        public static String SayHello(string name)
        {
            return "welcome to site " + name;
        }

    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    SQLyog连接mysql8,报错1251
    Oracle日期函数
    git 回退
    git新建分支并指定拉去远程分支
    git创建分支并拉去远端分支代码
    git创建空白分支
    Maven 本地仓库明明有jar包,pom文件还是报错解决办法(Missing artifact...jar)
    SqlHelper类
    ADO.NET中的模型及对象
    MVC过滤器---异常处理过滤器
  • 原文地址:https://www.cnblogs.com/wpf123/p/2052968.html
Copyright © 2011-2022 走看看