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之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    动态存储区(堆)、动态存储区(栈)、静态存储区、程序代码区
    auto, extern, register, static
    #include <iomanip>
    use
    ZooKeeper某一QuorumPeerMain挂了
    python 中的 字符串 列表 元祖 字典
    JAVA的23种设计模式
    spark job分析
    Spark1
    SQL三大范式
  • 原文地址:https://www.cnblogs.com/wpf123/p/2052968.html
Copyright © 2011-2022 走看看