Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted

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 :)
 
Share this answer
 
You can add controls dinamically on serverside.

On serverside you have to find first of all your placeholder. (for example: div, form)
And the end of the process you can add a new LiteralControl or your DropDownList to your placeholder.

You can use this as the follows:
C#
Control myPlaceHolder = FindControl("form1");

DropDownList drop = new DropDownList();

drop.ID = "yourDropDownList";

drop.DataValueFiled = "id";
drop.DataTextField = "name";

drop.DataSource = //your datasource

myPlaceHolder.Controls.Add(drop);

//literal
myPlaceHolder.Controls.Add(new LiteralControl("<div>something</div>"));


I hope I could help you! Let me know if something is missing.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900