Nodes New Locations Don't Stick

2 posts, 0 answers
  1. Don
    Don avatar
    40 posts
    Member since:
    Apr 2009

    Posted 04 Aug 2014 Link to this post

    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);
    }
  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 07 Aug 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top