如何在服务器上访问jQuery的TreeView控件? [英] How access Jquery TreeView on the server?

查看:106
本文介绍了如何在服务器上访问jQuery的TreeView控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在形式访问Jquery的树形目录在.aspx文件中提交?
另外,我可以添加节点jQuery的树形目录上飞? (在客户侧)

How do I access Jquery Treeview inside the .aspx file upon form submit? also, Can I add nodes to Jquery Treeview on the fly? (on the client side)

我使用asp.net web表单,C#

I am using asp.net web forms, c#

编辑:
有人提到的一个问题如下:
关于表单提交,有人将不得不写code中的客户端上收集数据,并通过Ajax发送到服务器的方法

EDITED: someone mentioned the following in one of the questions: "on form submit, someone is going to have to write code on the client to collect that data and send it via Ajax to a server method"

这是怎么做?????

how is this done?????

推荐答案

嗯,我想我找到了你想要的东西。看看这里

Well, I think I've found what you want. Take a look here.

在简单地说,你必须在你的服务器端定义一个WebMethod,然后你可以使用jQuery很容易地访问它。一个多方位的合作例子是链接下以上,在这里我将修改它来说明如何传递参数。所以......

In brief, you must define a WebMethod on your server side, and then you can easily access it using jQuery. An exellent working example is under the link above, and here I'll modify it to show how you can pass arguments. So...

在您的网页code-背后*的.cs:

In your page code-behind *.cs:

// We'll use this class to communicate
public class Dog
{
    public string Name { get; set; }
    public string Color { get; set; }
}

// This is your page, in my case Default.aspx
public partial class _Default : System.Web.UI.Page
{
    [WebMethod]
    public static string ProcessData(Dog myDog)
    {
        return "Your " + myDog.Color + " dog's name is " + myDog.Name + "!";
    }
}

然后在你的*的.aspx:

Then on your *.aspx:

<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="json2.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function() {
        $("#btnProcess").click(function() {
            // This is what we want to send to the server
            var dogItem =
            {
                 Color: $("#txtColor").val(),
                 Name: $("#txtName").val()
            };

            // And this is how it should be sent - in serialized way
            var dogItemSerialized = JSON.stringify(dogItem);

            $.ajax({
                type: "POST",
                url: "Default.aspx/ProcessData",
                data: "{'myDog':" + dogItemSerialized + "}",    
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("#result").text(msg.d);
                }
            });
        });
    });

</script>
Color: <input id="txtColor" type="text" /><br />
Name: <input id="txtName" type="text" /><br />
<input id="btnProcess" type="button" value="Click Me" />
<div id="result"></div>

所以在这里您填写文本框,然后你的数据被发送到将其理解为一个狗对象的服务器。注意传递参数,因为这是最令人困惑的部分。你应该通过他们JSON格式,这是一个有点太备受弦。所以,我在这里使用json2.js脚本,这有助于平时的JavaScript对象转换为JSON序列化的字符串(JSON.stringify()方法)。它可以这里。但它仍然是相当丑陋=),我传递的说法叫myDog,它的值是序列化dogItem是很重要的。因为这正是服务器期望得到(因此,例如,我不能改变参数名,这种将无法正常工作

So here you fill textboxes and then your data is sent to the server which understands it as a Dog object. Pay attention to arguments passing, because this is the most confusing part. You should pass them in JSON format, which is a little bit "too-much-stringy". So I use here json2.js script which helps to convert usual javascript object into JSON-serialized string (JSON.stringify() method). It is available here. But it is still rather ugly =) It is important that I pass argument called "myDog" which value is the serialized dogItem. Because this is exactly what the server expects to get (so, for example, I can't change the argument name, this won't work:

data: "{'someAnotherArgumentName':" + dogItemSerialized + "}"

和的最后一件事。需要注意的是以下行:

And the last thing. Pay attention to the following line:

success: function(msg) {
            $("#result").text(msg.d);
         }

如果您正在使用ASP.NET之前3.5的工作(例如ASP.NET 2.0),那么你就需要编写只是$(#结果)。文本(味精 ),而不是 msg.d 。只有ASP.NET 3.5封装了所有的D成员的数据因为某种原因...

If you are working with ASP.NET prior to 3.5 (for example, ASP.NET 2.0), then you'll need to write just $("#result").text(msg) instead of msg.d. Only ASP.NET 3.5 encapsulates all the data under "d" member for some reason...

总之,上述文章中,你可以找到有用的链接(包括里面的文章,并在评论),所以你可以阅读更多有关参数,msg.d等。

Anyway, in the above article you can find useful links (both inside the article and in comments), so you can read more about arguments, "msg.d" and so on.

我希望这有助于!

这篇关于如何在服务器上访问jQuery的TreeView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆