Back to Post

Using the Editors Dynamic Control Demo

Here's a couple of demo Dynamic ASCX controls.

Demo 1

Below is a very simple Dynamic ascx control that's been added to this specific section.

It's ASCX content has been set to :

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <div class="well">
      <h5>
        My Demo 1
      </h5>
      <p>
        This is a Dynamic ASCX.  This content is stored in the definition of this specific
        Control in this section definition.  
      </p>
      <p>
        It's a very quick way to include some HTML into a page without creating a 
        dedicate ASCX in a Dynamic Assembly. 
      </p>
    </div>
  </div>
</div>

The Demo Control 1


My Demo 1

This is a Dynamic ASCX. This content is stored in the definition of this specific Control in this section definition.

It's a very quick way to include some HTML into a page without creating a dedicate ASCX in a Dynamic Assembly.


Demo 2 (DataSource Support)

Below is another Dynamic ascx control that's been added to this specific section.

This control has the WebPage for this page associated via the control's options. Doing so, as with other controls, exposes the WebPage for use with the Dynamic ASCX.

In this demo, we load the DataItem from the DataSource, cast it to the type WebPage before rendering the cName.SlugValue.

Here's the ASCX content for the control, which is included below :

<%@import namespace="Net4orce.Canvas.General.WebPages"%>

<% 

// Load the selected DataItem
loadDataItem();

// Cast the DataItem to the type
var webPage = oDataItem as WebPage;

// Stop rendering if cast failed
if( webPage == null ) { return; }

// Use webPage ...

%>


<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <div class="well">
      <h5>
        My Demo 2
      </h5>

      <p>
        The Slug Value of the <code>cName</code> propertry for the referenced <code>WebPage</code> is :
      </p>
      <p class="text-center">
        <code><%=webPage.cName.SlugValue%></code>
      </p>
    </div>
  </div>
</div>

The Demo Control 2


My Demo 2

The Slug Value of the cName propertry for the referenced WebPage is :

using-the-editors-dynamic-control-demo


Use With Care

In the demo 2 we need to import the Net4orce.Canvas.General.WebPages namespace.

As you can see, you have access to all the entire NetCanvas functionality that you also have with an ASCX control created in a Dynamic Assembly. Including access to the Application Object, DataBases, Session & User state, etc. This means you could build an entire site using these controls.

We do reccomend you use these Dynamic controls with care, they aren't backed by a git repository in the same way as a propper Dynamic Assembly ASCX is.

If you remove the control from a section, you delete the code along with it.