Articles in this section
Category / Section

How to perform Template binding in ASP.NET Web Forms Diagram?

2 mins read

You can embed the SVG, HTML element into node using templateId property and the embedded SVG, HTML elements can be bounded with node’s properties using JSRender templates.

Native Node

Diagram supports to embed SVG element into node. It is achieved by setting node shape’s type as ej.datavisualization.Diagram.Shapes.Native and assigns the template id to the shape’s templateId property.

Note:
  1. Refer to the “jsrender.min.js” file for template binding support.
  2. Template (HTML/ SVG tags) have to be retained in application side as only its ID is saved during Diagram’s save method.
  3. SVG or HTML element defined in script tag cannot be displayed in the browser.

 

The following code illustrates how a Native node is created.

JS

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  
var node = {
            shape: { type: ej.datavisualization.Diagram.Shapes.Native,                 templateId: "svgTemplate" },
            text:"Mail";
        }

CSHTML

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  

Controller

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Native);
//Set the templateId
node.Shape.TemplateId = "svgTemplate";
node.Text="Mail";

ASPX

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  

ASPX.CS

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Native);
//Set the templateId
node.Shape.TemplateId = "svgTemplate";
node.Text="Mail";

 

Render a SVG node

Figure 1: Native Shape

HTML Node

You can embed the HTML elements in Diagram through HTML shape node. It is achieved by setting node shape’s type as ej.datavisualization.Diagram.Shapes.Html and assigns the template id to the shape’s templateId property. The following code illustrates how an HTML node is created.

JS

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>
  var node = {
            shape: { type: ej.datavisualization.Diagram.Shapes.Html, templateId: "htmlTemplate" },            
            value: "button"
        }

CSHTML

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>

Controller

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Html);
//Set the templateId
node.Shape.TemplateId = "htmlTemplate";
node.Value="button";

ASPX

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>

ASPX.CS

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Html);
//Set the templateId
node.Shape.TemplateId = "htmlTemplate";
node.Value="button";

 

Render an HTML node

Figure 2: HTML Shape


Note:

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied