Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic WebForm_Diagram: Create node on CallBack? (Read 6140 times)
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
WebForm_Diagram: Create node on CallBack?
Apr 16th, 2012 at 11:43am
Print Post  
Hi,

More stiupid questions. Embarrassed

Is it possible to create (for example) shapeNode on callback event, on server-side and bind it to client-side?
For now I'm able to create it on server-side, but unable to bind the creation to client-side.

Br. Henry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: WebForm_Diagram: Create node on CallBack?
Reply #1 - Apr 16th, 2012 at 1:13pm
Print Post  
Hi,

What do you mean by binding a node to the client side, and what client mode are you using? Generally if you add a new node to the diagram from a Page_Load server event, it should appear in the client applet when the browser loads the page. If you need to initialize the new node with some client code, you could do that from an AppletStartedScript handler - the new node will be the last one in the diagram.Nodes collection. If you are creating more than one nodes per request on the server, you could mark them as uninitialized via some property (e.g. set Text or Tag to "uninitialized") and process such nodes on the client.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: WebForm_Diagram: Create node on CallBack?
Reply #2 - Apr 17th, 2012 at 5:50am
Print Post  
Hi,

- ClientSideMode = JavaApplet
- Binding: When node is created on server side on callback it will not bind to client-side; this is needed to be done by javascript (so far how I've understood). (Page/controller doesn't update)


To be more specific on my case:
- After page is loaded
- User Clicks canvas
- A new node is created (on server-side by callback)
- Data is stored to Session["DiagramObjInSession"] (example) (and maybe some other related actions are taken)
- (This is the part what I'm asking) Coming out from Callback, client view should be updated (well apparently this needs to be handled by javascript). Now server-side has information of actions done by client-side but data from both sides are cut from each and other. In the session there is information of created node but this information is not bound on postback... (on postback I do "quick watch" in visual studio and check the count of nodes... it is increasing (on clicking), but none of them is bound to client view... I tried, Diagram.BindData(), but this doesn't do the job,..)

Br. Henry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: WebForm_Diagram: Create node on CallBack?
Reply #3 - Apr 17th, 2012 at 6:39am
Print Post  
Hi,

So you are calling a service method that adds a node to a diagram stored in the session? In such case the applet won't know what happened on the server, and you will have to synchronize it manually.

One thing you could do is call Diagram.SaveToString on the server, and return the string as result of the service method. Then the applet can load the updated diagram data using the loadFromString method.

Alternatively, you could just create a new node both on the server and the client - they will correspond to the same object after a full postback.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: WebForm_Diagram: Create node on CallBack?
Reply #4 - Apr 17th, 2012 at 7:12am
Print Post  
Yes, that was the idea, but I'm unable to read: stream that was saved after node was created (on postback; all data in stream is correct though..),  XML that is stored to session... cut the chase, I'm unable to load anything (FromString, FromStream, FromXML... nothing). No errors are occurred, but no work is done ether..  could you throw an example case of session stored (stream for example, string will also do..) that is being loaded and stored. For example in button click. (a demo project or a solution for viewing...). Btw.. on stream I'm using MemoryStream, hope that isn't a problem Smiley

Br. Henry
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: WebForm_Diagram: Create node on CallBack?
Reply #5 - Apr 17th, 2012 at 8:44am
Print Post  
I was able to what I wanted by writing the diagram to a file. But this is not what I want as for file handling there is problem because in my case all "settings" that is being drawn to the diagram comes from another config file. Which has nothing to do with the diagram it self but the content of diagram ("not what, but how"). So I wish I could store all user handled diagram related data in session (memory), and handle the config file separately by the modification that user has done to the diagram and handling data between client and server by flashing windows is not user friendly... Smiley

Br. Henry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: WebForm_Diagram: Create node on CallBack?
Reply #6 - Apr 17th, 2012 at 10:49am
Print Post  
Hi,

The following code worked in my test site. To spare the bandwidth, you can further extend it to send only Json strings that describe the new nodes (e.g. [label:"...", coordinates:"...", color:"..."]) and create nodes from JavaScript based on the Json content, instead of reloading the diagram.

Note that if the user draws anything, it will be lost after clicking the "new node" button, because the applet changes are not sent to the callback method. If your application lets users draw interactively, you could send the applet's saveToString() result as argument to the callback instead of using the session data.

I hope that helps,
Stoyan

Code
Select All
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="MindFusion.Diagramming.WebForms" Namespace="MindFusion.Diagramming.WebForms"
	TagPrefix="ndiag" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
    <div>
		<ndiag:DiagramView runat="server"
			ID="diagramView"
			Width="800px" Height="600px">
		</ndiag:DiagramView>
    </div>
    </form>
    <br />
    <button id="btnNewNode"
		onclick="newNode('', '')">
		New node
	</button>
</body>

<script type="text/javascript">
function diagramReceived(result, context)
{
	var applet = <%= diagramView.AppletElement %>;
	applet.loadFromString(result);
}
</script>

</html>

using System;
using System.Web.UI;

using MindFusion.Diagramming;


public partial class _Default : Page, ICallbackEventHandler
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
		{
			// upon initial GET, save the empty diagram as session variable
			var diagram = Session["Diagram"];
			if (diagram == null)
				Session["Diagram"] = diagramView.Diagram.SaveToString(SaveToStringFormat.CompressedXml, false);
		}

		ClientScriptManager cm = Page.ClientScript;
		String callback = cm.GetCallbackEventReference(
			this, "arg", "diagramReceived", "");
		String newNode = "function newNode(arg, context) {" +
			callback + "; }";
		cm.RegisterClientScriptBlock(GetType(), "newNode", newNode, true);

    }

	public string GetCallbackResult()
	{
		var diagram = new Diagram();
		diagram.LoadFromString(Session["Diagram"].ToString());
		diagram.Factory.CreateShapeNode(r.Next(100), r.Next(50), 30, 15)
			.Text = "node " + diagram.Nodes.Count;

		var str = diagram.SaveToString(SaveToStringFormat.CompressedXml, false);
		Session["Diagram"] = str;
		return str;
	}

	public void RaiseCallbackEvent(string eventArgument)
	{
	}

	Random r = new Random();
}
 

  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: WebForm_Diagram: Create node on CallBack?
Reply #7 - Apr 19th, 2012 at 7:50am
Print Post  
Yes, that does the trick... this as a reference I found solution to my case. (I have 3th-party component to handle custom-callbacks which has its own relations to other components in its assembly).

It is sad that this is needed to be done manually or by 3th-party components; it would be great if the component would have this function within it self... (Example cases at DevExpress)

Thank you.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: WebForm_Diagram: Create node on CallBack?
Reply #8 - Apr 19th, 2012 at 10:21am
Print Post  
Hi,

I could not understand what built-in function do you need - updating a session diagram after client events, or something more generic like calling server event handlers? What exactly do you do with DevExpress controls?

Stoyan
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: WebForm_Diagram: Create node on CallBack?
Reply #9 - Apr 19th, 2012 at 12:55pm
Print Post  
In this current case and specific situation I handle only callbacks...

for in raw example:
What I meant was that for example in devexpress (some) control(s) has/have its own callbacks that includes all target controls related properties and methods carried through the callback. I hope I described this feature in a correct and understandable way...  Embarrassed
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint