5,693,936 members and growing! (16,742 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Controls     Intermediate

AJAX Dirty-Panel

By Cassio Mosqueira

This is a Panel that automatically shows an alert if the user tries to leave the page before saving the data.
Javascript, XML, HTML, Windows, .NET, Visual Studio, WebForms, Ajax, ASP.NET, Dev

Posted: 30 Apr 2007
Updated: 30 Apr 2007
Views: 30,759
Bookmarked: 46 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
21 votes for this Article.
Popularity: 4.97 Rating: 3.76 out of 5
2 votes, 9.5%
1
1 vote, 4.8%
2
0 votes, 0.0%
3
2 votes, 9.5%
4
16 votes, 76.2%
5

Introduction

Have any of your users ever told you that after filling that long data entry form he accidentally closed the browser or moved to another page and forgot to click the save button? I heard this story more than once, and at the end my responses I often told he user something like "Well, you should pay more attention when you're filling out a form." Of course, I didn't say it using these words, but that was the only thing we could say.

In fact, keeping track of fields that were changed in classical ASP.NET forms is not an easy task. Since every postback fires the onbeforeunload event, there was no generic way of knowing if the postback was intentional or not. So we had to write a lot of custom JavaScript to manage that.

Now in the AJAX world, this limitation is gone. If we have a 100% "ajaxfied" page, the onbeforeunload event will fire only if the user actually leaves the page. It makes our lives much easier.

This is a Panel that automatically detects if any control inside it was changed and shows an alert if the user tries to leave the page before saving the data.

Click here to see a sample page.

Using the code

Once again I am using the Anthem.NET library to give AJAX functionality. This webcontrol inherits from the Anthem Panel, so what you need to do is to put all your data entry controls within this panel and set the property OnLeaveMessage. This property corresponds to the message that will be shown when the user tries to leave the page without saving its contents. When the user actually clicks the save button, you need to tell the panel to store the new values so it won't show the alert when the user leaves the page. This is done by calling the panel's Reset method when the data is saved.

The download file contains the webcontrol and a sample page.

Conclusion

This is a simple to use, yet very useful webcontrol that can enhance the usability of your web application.

I hope you enjoy it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Cassio Mosqueira


I've been developing .NET enterprise applications since 2002.

I am originally from Rio de Janeiro and I am currently working as a developer for Sales Resource Group in Oakville, Ontario.

I'm vegetarian and I like surfing and listening to progressive metal bands like Dream Theater and Pain of Salvation.

Check out my blog!

Occupation: Web Developer
Location: Brazil Brazil

Other popular Ajax and Atlas articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
QuestionAJAX 1.0 (w/o anthem)memberdB.20:38 6 Aug '07  
AnswerRe: AJAX 1.0 (w/o anthem)memberCassio Alves21:41 6 Aug '07  
GeneralRe: AJAX 1.0 (w/o anthem)memberdB.17:41 10 Aug '07  
Generalasp:FormView - Not WorkingmemberQasim Javed3:30 18 Jul '07  
GeneralRe: asp:FormView - Not WorkingmemberCassio Alves21:44 6 Aug '07  
GeneralTooltip Image Datamemberngovanphuc0:54 13 Jul '07  
Generalit does not work when you have item template in grid view [modified]membertahhan20:44 11 May '07  
GeneralRe: it does not work when you have item template in grid viewmemberCassio Alves5:55 12 May '07  
GeneralPerfect timingmemberBryan Avery0:05 9 May '07  
GeneralVery coolmemberMichael J. Collins9:09 8 May '07  
GeneralRe: Very coolmemberCassio Alves11:42 8 May '07  
GeneralRe: Very coolmemberzhulei_2016:32 9 May '07  
GeneralDoesn't work in Opera 9.20memberrichzilla8:48 8 May '07  
GeneralRe: Doesn't work in Opera 9.20memberCassio Alves11:52 8 May '07  
Generalhow to use control on on tab pagememberjust_kideng19:58 7 May '07  
GeneralRe: how to use control on on tab pagememberCassio Alves5:01 8 May '07  
GeneralRe: how to use control on on tab pagememberjust_kideng22:27 8 May '07  
GeneralNice work!memberTim Brats9:15 6 May '07  
GeneralCode project is not source repositorymemberMaruf Maniruzzaman17:35 30 Apr '07  
GeneralRe: Code project is not source repositorymemberCassio Alves18:49 30 Apr '07  
GeneralRe: Code project is not source repositorymemberMaruf Maniruzzaman19:26 30 Apr '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Apr 2007
Editor: Sean Ewington
Copyright 2007 by Cassio Mosqueira
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project