Detecting change in CuteEditor for ASP.NET

In a project I am using CuteEditor for wysiwig html editing, in this case, for web pages. I found that I need to know in javascript if the user has made changes to the html so that I can pop up a confirm dialog before posting back and losing any potential changes.

I tried for a while to use the javascript API as docuemented on the CuteEditor site, trying attachEvent and addEventListener to set a flag on keyup or keydown, but to no avail. Adding events to CuteEditor turned out to be rather difficult, and not particularly well documented.

Time for another approach – by inspecting the editor object in javascript I found that magically is has an IsDirty() method! this returns a boolean telling me if the user has made changes. Goodbye to adding event listeners and setting flags as the CuteEditor knows when it’s been changed!

 

var editor1 = document.getElementById("<% =Editor1.ClientID %>");
if (editor1.IsDirty() == true) 
alert("HTML has been changed!");
Advertisements
This entry was posted in ASP.NET, Web Devleopment and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s