Graciously Hosted by MaximumASP        

Using the ASP.NET AJAX Editor Control to Implement In-Place Content Editing.

In-Place editing is a slick feature for managing some of a web sites content.

I’ve mocked up a demo of In-Place editing using the new ASP.NET Ajax Control Toolkit’s Editor control and the ASP.NET Multi-View control.

Also, I’m implementing this as a User Control so it can be easily and widely used throughout my project.

Here’s how it works.

Note the little “Pencil” on the top / right of the content are. If you hover over it you get an edit hint.

7-9-2009 10-49-53 AM 

When you click on it you enter edit mode.

Note the Ajax style behavior accomplished by a combination of using ASP.NET’s MultiView control and ASP.NET Ajax’s UpdatePanel.

 

7-9-2009 10-50-39 AM

Now some rich text entry.

7-9-2009 10-52-33 AM

Clicking on the Floppy Disk Icon “Saves” the new content (actual persistence is not yet implemented) and clicking on the X cancels.

Hovering over the icons provides guidance. Note that the Editor Sizes with the text area. 

Click save and ….

7-9-2009 10-52-54 AM

Presto.

Here are a few implementation details …..

First, lets look at the control in design view.

7-9-2009 11-12-16 AM

… the markup

   1:  <asp:UpdatePanel ID="InPlaceEditorCOntrolUpdatePanel" runat="server">
   2:  <ContentTemplate>
   3:  <asp:MultiView ID="EditInPlace_MultiView" runat="server" ActiveViewIndex="0">
   4:     <asp:View ID="DisplayView" runat="server">
   5:         <asp:Panel ID="ContentDisplayPanel" runat="server">
   6:         <p style="text-align: right">
   7:            <asp:ImageButton ID="Edit_ImageButton" runat="server" Height="16px" 
   8:                             ImageUrl="~/InPlaceEditorControl/Images/Edit_Icon.png" 
   9:                             Width="16px" 
  10:                             ToolTip="Click to Enter Edit Mode" 
  11:                             onclick="Edit_ImageButton_Click" />
  12:         </p>
  13:         <asp:Label ID="ContentLabel" runat="server" Width="100%"></asp:Label>
  14:         </asp:Panel> 
  15:     </asp:View>
  16:     <asp:View ID="EditView" runat="server">
  17:         <asp:Panel ID="ContentEditPanel" runat="server">
  18:         <p style="text-align: right">
  19:            <asp:ImageButton ID="Save_ImageButton" runat="server" Height="16px" 
  20:                             ImageUrl="~/InPlaceEditorControl/Images/Save_Icon.png" 
  21:                             Width="16px" 
  22:                             ToolTip="Click to SAVE and Exit Edit Mode." 
  23:                             onclick="Save_ImageButton_Click" 
  24:                             />
  25:            <asp:ImageButton ID="Abort_ImageButton" runat="server" Height="16px" 
  26:                             ImageUrl="~/InPlaceEditorControl/Images/Abort_Icon.png" 
  27:                             Width="16px" 
  28:                             ToolTip="Click to Exit Edit Mode Without Saving." 
  29:                             onclick="Abort_ImageButton_Click" />
  30:         </p>
  31:         <act:Editor ID="ContentEditor" runat="server" Width="100%" Height="100%" 
  32:                 oncontentchanged="ContentEditor_ContentChanged" />
  33:         </asp:Panel>   
  34:     </asp:View>
  35:  </asp:MultiView>
  36:  </ContentTemplate>
  37:  </asp:UpdatePanel>

… and the code.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.UI;
   6:  using System.Web.UI.WebControls;
   7:   
   8:  public partial class InPlaceRichTextEditorControl : System.Web.UI.UserControl
   9:  {
  10:   
  11:      private int _ContentHeight;
  12:      public int ContentHeight
  13:      {
  14:          get
  15:          {
  16:              return _ContentHeight;
  17:          }
  18:          set
  19:          {
  20:              _ContentHeight = value;
  21:          }
  22:      }
  23:   
  24:      private int _ContentWidth;
  25:      public int ContentWidth
  26:      {
  27:          get
  28:          {
  29:              return _ContentWidth;
  30:          }
  31:          set
  32:          {
  33:              _ContentWidth = value;
  34:              ContentDisplayPanel.Width = _ContentWidth;
  35:              ContentEditPanel.Width = _ContentWidth;
  36:          }
  37:      }
  38:   
  39:      protected void Page_Load(object sender, EventArgs e)
  40:      {
  41:          
  42:      }
  43:   
  44:      protected void Edit_ImageButton_Click(object sender, ImageClickEventArgs e)
  45:      {
  46:          ContentEditor.Content = ContentLabel.Text;
  47:          EditInPlace_MultiView.SetActiveView(EditView);
  48:      }
  49:   
  50:   
  51:   
  52:      protected void Abort_ImageButton_Click(object sender, ImageClickEventArgs e)
  53:      {
  54:          EditInPlace_MultiView.SetActiveView(DisplayView);
  55:      }
  56:   
  57:      protected void Save_ImageButton_Click(object sender, ImageClickEventArgs e)
  58:      {
  59:          ContentLabel.Text = ContentEditor.Content;
  60:          EditInPlace_MultiView.SetActiveView(DisplayView);
  61:      }
  62:      protected void ContentEditor_ContentChanged(object sender, EventArgs e)
  63:      {
  64:   
  65:      }
  66:  }

And yes, I think this is NOT FINISHED.

Thoughts, suggestions ?

Technorati Tags: ,,,

» Similar Posts

  1. Implementing a jQuery Modal Window in ASP.NET
  2. Proving the performance of Static Properties.
  3. .NETOOP Global Statics Update

» Trackbacks & Pingbacks

  1. Pingback from Using the ASP.NET AJAX Editor Control to Implement In-Place Content Editing. : Misfit Geek

  2. Pingback from Using the ASP.NET AJAX Editor Control to Implement In-Place Content Editing. | I love .NET!

  3. Pingback from Using the ASP.NET AJAX Editor Control to Implement In-Place Content Editing. | Nexo IT - Information Technology News

  4. Thank you for submitting this cool story - Trackback from ravipendigg

  5. Pingback from News Using the ASP.NET AJAX Editor Control to Implement In-Place … | Web 2.0 Designer

  6. Thank you for submitting this cool story - Trackback from progg.ru

  7. Pingback from Dew Drop – July 15, 2009 | Alvin Ashcraft's Morning Dew

  8. Thank you for submitting this cool story - Trackback from DotNetShoutout

  9. Daily tech links for .net and related technologies - July 14-17, 2009 Web Development ASP.NET Membership

  10. Pingback from Using the ASP.NET AJAX Editor Control to Implement In-Place … | Webmaster Tools

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

    asp.net news (July 17th) - Jack is Here — July 16, 2009 9:37 PM
  12. Pingback from In-Place Editing using the ASP.NET AJAX Editor Control « Dev42 and Friends

» Comments

  1. Gilad avatar

    Great post thank you.

    Is there a way to add an image upload or attachment inside the editor text? just like ms word?

    Gilad — July 14, 2009 10:31 AM
  2. Joe Stagner avatar

    There is not, but as I eveolve the user control there are two additions that I intend to make.

    1.) Suport a choice of different HTML Editors (FTB, etc.)

    2.) Suport a CUSTOM version of the ACT COntrol - to which we could add the functionality you suggest.

    Joe Stagner — July 14, 2009 10:33 AM
  3. Gilad avatar

    OK thanks

    Gilad — July 14, 2009 10:40 AM
  4. Joshua avatar

    I'm curious to see what you come up with as far as supporting other HTML editors. I gave up on trying to get them to work in an UpdatePanel, but hopefully you'll have better luck.

    I think your example should have UpdateMode="Conditional" for your UpdatePanel.

    It's nice to see that the ASP.NET AJAX controls are still being developed.

    Joshua — July 14, 2009 11:38 AM
  5. Hemen avatar

    When I click on the pencil icon on the demo site it takes some time for the editor to load about 30 seconds or so. Till that time there is no visual notification that there is some processing being done. May be a visual icon of a spinning wheel or the clock can give an idea to the user that he/she needs to wait.

    Hemen — July 14, 2009 11:59 AM
  6. Hemen avatar

    Also noticed that the control does not come up properly in IE6

    Hemen — July 14, 2009 12:01 PM
  7. Joe Stagner avatar

    Hemen - already implemented in my working copy :)

    As to IE 6, how DOES it "come up" ?

    Joe Stagner — July 14, 2009 12:42 PM
  8. Vijay avatar

    It's nice to see that the ASP.NET AJAX controls.

    Is it working for all the browsers like opera, firefox 2.0 or greater, i.e.8 etc?

    Vijay — July 14, 2009 2:46 PM
  9. Vijay avatar

    How to apply a styles(CSS function)?

    Vijay — July 14, 2009 2:48 PM
  10. sosmary avatar

    Joe,

    Thanks for the neat demo. Ajax rocks!!!

    sosmary — July 14, 2009 3:35 PM
  11. Khaled Diab avatar

    Great work, Joe

    but, When shall we start to design and write a code ?

    Khaled Diab — July 14, 2009 5:27 PM
  12. Hemen avatar

    When I tried in the morning all i could see is the save and 'X' icon buttons on the top right corner and two lines.. When I tried some time back it does show the control but the height is not identical to that in Firefox.

    Screenshot for IE6 : i648.photobucket.com/.../untitled.png

    Hemen — July 14, 2009 6:46 PM
  13. Ahmed avatar

    It looks great tool

    Thanks for the demo, I hope it will work with all browsers

    Ahmed — July 15, 2009 1:05 AM
  14. Pat Woods avatar

    For the record:

    Firefox 3.5 took about 20 secs

    Chrome 2.0 didn't work, after about 5 secs the disk and cross icons show with what looks like the top edge only of the control showing

    Opera 9.64 took about 18 secs

    Safari 4.0 same as Chrome.

    I guess these would be called MAJOR clients as per the original spec.

    Pat Woods — July 15, 2009 7:16 PM
  15. bennyb avatar

    UpdatePanel?

    Are you kidding me?

    I just lost faith in this project

    bennyb — July 18, 2009 10:39 AM

Comments are closed