This is a migrated thread and some comments may be shown as answers.

Nodes New Locations Don't Stick

1 Answer 13 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 04 Aug 2014, 01:38 PM
I created a little test application to look at this control and I'm having a weird issue. I am doing this all programmatically server side. So I added a couple of nodes to the diagram when it starts and then added a button that adds another node to the diagram. If I move the nodes, when the app posts back to add a new node the nodes that were moved revert back to their original position. Is there something else I need to do like capture something on the node moved event?

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        MapDiagram.BorderStyle = BorderStyle.Solid;
        MapDiagram.BorderColor = Color.Black;
        MapDiagram.Resizable = false;
        List<MapTask> tasks = MapHelper.GetSampleTasks(4);
        AddTasksToMap(tasks);
    }
}
 
private void AddTasksToMap(List<MapTask> tasks)
{
    foreach (MapTask task in tasks)
    {
        DiagramShape shape1 = new DiagramShape()
        {
            Width = 50,
            Height = 50,
            Type = "rectangle",
            X = task.XPosition,
            Y = task.YPosition
        };
        shape1.ContentSettings.Text = task.Description;
        MapDiagram.ShapesCollection.Add(shape1);
    }
}
 
protected void BtnAddTaskClick(object sender, EventArgs e)
{
    Random r = new Random();
    DiagramShape shape1 = new DiagramShape()
    {
        Width = 50,
        Height = 50,
        Type = "rectangle",
        X = (r.Next(900)),
        Y = (r.Next(640))
    };
    shape1.ContentSettings.Text = "New Task";
    MapDiagram.ShapesCollection.Add(shape1);
}

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 07 Aug 2014, 12:19 PM
Hi Don,

Changes in the position of the RadDiagram shapes are not stored in ViewState, which leads to the examined resetting of the position of the shapes when postback is initiated.

You can implement persistence of the position of the diagram shapes by using the JSON import and export feature of the control: http://demos.telerik.com/aspnet-ajax/diagram/examples/saveload/defaultcs.aspx. This will requite storing the generated JSON on the server when a postback is started then retrieving and importing it in the diagram when the page is loaded.

Another possible approach is to use the client-side API of the diagram (http://www.telerik.com/help/aspnet-ajax/diagram-client-side.html) to add the shapes on the client, so that performnig a postback is not required.

Regards,
Slav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Diagram
Asked by
Don
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or