I’ve added persistence to the “In-Place-Editor” control at .NETOOP  using SQLExpress and the LINQ to Entities.

Since the Control itself can be used for ANY text content, the page that contains the control is responsible for population and persistence.

Note the code below. The control is populated by the first notice in the notices table (other use may use multiple records.)

Of particular interest is the push back to the database.

Note that this code is called from the Page_SaveStateComplete event handler.

NETOOP_DataEntities ctx = new NETOOP_DataEntities();
protected void Page_Load(object sender, EventArgs e)
// Populate the In-Place Editor Control
var result = ctx.NETOOP_AnnouncementSet.Where(p => p.Id == 1);
if (!IsPostBack)
NETOOPNoticeEditor.Content = result.First().ContentText;
protected void Page_SaveStateComplete(object sender, EventArgs e)
// Push Edited Changes back to the database. 
// This can NOT be done in the Page_Load event becuase the 
// "DataDirty" flag gets set in a control event which doesn't
// fire until after Page_Load
if (NETOOPNoticeEditor.ContentIsDirty)
var result = ctx.NETOOP_AnnouncementSet.Where(p => p.Id == 1);
result.First().ContentText = NETOOPNoticeEditor.Content;

It needs to be done here because the dirty content flag is set in the Editor Control’s “ContentChanged” event handler.

protected void ContentEditor_ContentChanged(object sender, EventArgs e)
ContentIsDirty = true;
ViewState[this.ID.ToString()] = ContentEditor.Content;
Content = ContentEditor.Content;

The ContentChanged event fires AFTER the Page_Load event so we need to move the “Save” call to later in the Lifecycle.

Note also the explicit ViiewState population which is necessary to maintain the user edits on post-back.

Some MISSING items …… 

  • Save Exception Handling
  • Safari / Chrome Support (This is a multi-view control issue.)
  • Security – (No role constraints, anyone can edit.)
  • Multiple Announcement Record Support


Technorati Tags: ,,NETOOP,,