动态添加控件 [英] dynamic Adding controls

查看:60
本文介绍了动态添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请告诉我如何在页面上添加动态控件并将其拖放到asp.net中。我还需要将这些控件及其位置保存到数据库中。



提前谢谢

Kuldeep Dwivedi

解决方案

我想你想在Web应用程序中模拟Visual Studio的工具包。您将拥有一个用户可以添加的控件列表,然后拖放到页面中的给定位置。然后你需要保存控件的id和用户放置它的位置。



你可以这样做。但是由于html的流布局特性,你需要使用一些黑客来设计这个功能。



1.将你的掉落区分成几个部分,每个部分part将具有用作drop-target的标识符。当用户在此处删除控件时,您将保存控件的ID和此标识符。

2.将所需的所有控件类型放在一个单独的位置。在每个控件中,添加您想要用于跟踪的其他自定义属性。

3.使用jquery ui的可拖动和可放置的小部件( http://jqueryui.com/droppable/ [ ^ ]

4.完成拖动事件后,将拖动对象的id与属性和drop容器ID一起使用,并使用ajax将其保存到DB。对拖动的事件id进行克隆(

( mycontainer_4)。附加(

( 控制)。克隆())并将其放在容器中。之后返回false,以便取消主拖放事件。否则控件将从拖动区域移除。



希望基本的想法对你有用。如果你遇到任何重大障碍,请告诉我。如果有效,请标记答案:)


Hi,

Please let me know how I can add dynamic controls on page and drag and drop that in asp.net. I also need to save that controls and their position into db.

Thanks in advance
Kuldeep Dwivedi

解决方案

I suppose you want to simulate the Visual Studio's toolkit in a web app. You would be having a list of controls which the user can add, and then drag/drop to a given location within the page. Then you need to save the id of the control and the position where it was placed by the user.

You can do that. However due to the flow-layout nature of html, you need to use some hacks to design this functionality.

1. Divide your drop zone into several parts, where each part will be having an identifier to be used as drop-target. When user drops a control here, you save the control's id and this identifier.
2. Place all the control types you want in a separate location. Within each control, add additional self defined properties you want be used for tracking.
3. Use jquery ui's draggable and droppable widgets (http://jqueryui.com/droppable/[^]
4. Once the drag event is completed, take the dragged object's id along with properties and the drop container id and save it to DB using ajax. Do a clone of the dragged event id (


("mycontainer_4").append(


("control").clone()) and place it within the container. After this return false so that the main drag/drop event is cancelled. Else the control will get removed from the drag area.

Hope the basic idea works for you. Let me know if you face any major obstacle. If it works, please mark as answer :)


这篇关于动态添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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