javascript,pagemethods

原文地址:http://hi.baidu.com/wizardchilde/item/abc8dc11a25414e65f53b1df

javascript 是使用js来控制html dom 的脚ben语言。

/*给树加载数据*/
function getTreeData(id,parentCode,procName,status,clickcallback)
{
    if($("#"+id).find(">ul").html()=="" || $("#"+id).find(">ul").html()==null){
        var thisdata=storage._get(parentCode);
        if(thisdata=="" || thisdata==null || status== "0"){
            PageMethods.GeTreeInfoForClient(procName,parentCode,treeResult);
        }
        else{
            $("#"+id).find(">ul").append(thisdata+"");
            treeInit();
        }
    }
    function treeResult(result){
        var appendCode="";       
        for(var i=0;i<result.length;i++){
           appendCode=(result[i].ExistChind ? '<li id="'+result[i].Code+'"><span>'+result[i].Name+'</span><ul></ul></li>' : '<li id="'+result[i].Code+'"><span>'+result[i].Name+'</span></li>');
           $("#"+id).find(">ul").append(appendCode);                          
        }
        storage._set(parentCode,$("#"+id).find(">ul").html());
        treeInit();
    }
    function treeInit(){
        $("#"+id).find(">ul").find("span").dblclick(function(){
            if(clickcallback){//双击树上结点时的回调事件
                clickcallback.apply(this,arguments);
            }
        }).hover(function(){$(this).addClass("spanhover");},function(){$(this).removeClass("spanhover");}); 
        $("#"+id).treeview({//此节点构建其下的tree
            collapsed: true,
            toggle:function aa(){
                getTreeData($(this).attr("id"),$(this).attr("id"),procName,null,clickcallback);
            }}
        );
    }
}

pagemethods对象是由微软的<asp:ScriptManager enablepagemethod="true">而生成的页面js对象

此对象包含后台方法[后台类应加上"[System.Web.Script.Services.ScriptService]"特性;后台方法应标记为"[WebMethod]"]

C#:

[System.Web.Script.Services.ScriptService]
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        [WebMethod]
        public static string MyCSharp(string a)
        {
            return a;
        }

    }

html:

<body οnlοad="ExecCSharp()">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    </form>
</body>

js:

<script type="text/javascript">
        function ExecCSharp() {
            PageMethods.MyCSharp("a", sucss);
        }
        function sucss(data) {
            alert(data);
        }
    </script>

aspx:

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

或者将其写到web.config中

js的面向对象,下次说.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值