Misfit Geek

Fustrated by Design !

MaximumASP

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;
        ctx.SaveChanges();
    }
}

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

 

Similar Posts:

Comments

There are 13 comments for this post.

  1. Adding Persistence to the .NETOOP Edit in Place control. : Misfit Geek on July 16, 2009 12:48 pm

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Adding Persistence to the .NETOOP Edit in Place control. : Misfit Geek

  2. rickj on July 16, 2009 1:30 pm

    Good job Joe this is going to be a good lesson on the EF and also how to stop attacks coming from the editor you touched on that in your video at http://www.asp.net/…/video-7115.aspx

    I been checking out the source on codeplex it looks clean and simple good work

    I’ve been looking for a good article on HD web cams in ASP.NET

    I haven’t found a good one yet if there is one it would be good to know

    on more thing have you started the videos for this project yet

  3. Adding Persistence to the .NETOOP Edit in Place control. | I love .NET! on July 16, 2009 4:19 pm

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Adding Persistence to the .NETOOP Edit in Place control. | I love .NET!

  4. The Technology Post for July 16th, 2009 | I love .NET! on July 16, 2009 4:20 pm

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from The Technology Post for July 16th, 2009 | I love .NET!

  5. Evan Larsen on July 16, 2009 4:40 pm

    I went to codeplex to look at the source code and couldn’t find anything related to what you just blogged about.. am I missing something?

  6. Thom on July 16, 2009 4:42 pm

    Probably just not revved on codeplex yet, see the dates.

  7. asp.net news (July 17th) - Jack is Here on July 16, 2009 9:37 pm

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from asp.net news (July 17th) – Jack is Here

  8. The Technology Post for July 16th, 2009 | rapid-DEV.net on July 17, 2009 4:31 am

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from The Technology Post for July 16th, 2009 | rapid-DEV.net

  9. Adding Persistence to the .NETOOP Edit in Place control. | rapid-DEV.net on July 17, 2009 4:42 am

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Adding Persistence to the .NETOOP Edit in Place control. | rapid-DEV.net

  10. Steven on July 17, 2009 4:46 am

    - ViewState[this.ID.ToString()] = ContentEditor.Content;

    Why oh why do people call the .ToString() method on strings???

  11. Adding Persistence to the .NETOOP Edit in Place control. : Misfit Geek | Webmaster Tools on July 17, 2009 6:29 am

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Adding Persistence to the .NETOOP Edit in Place control. : Misfit Geek | Webmaster Tools

  12. Dew Drop – July 17, 2009 | Alvin Ashcraft's Morning Dew on July 17, 2009 8:18 am

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Dew Drop – July 17, 2009 | Alvin Ashcraft’s Morning Dew

  13. Adding Persistence to the .NETOOP Edit in Place control. | ASP Scribe on July 22, 2009 11:45 am

    RE: Adding Persistence to the .NETOOP Edit in Place control.

    Pingback from Adding Persistence to the .NETOOP Edit in Place control. | ASP Scribe

Write a Comment

Let me know what you think?