Design Question

  • Thread starter Thread starter epigram
  • Start date Start date
E

epigram

I'm going to be building an asp.net appliction. Something typical that I
imagine is I will have a .aspx page that will have multiple controls in a
form. The user can make changes to the controls (e.g. change text in a text
box, change a drop down list selection), but may not choose whatever action
is required to post the form. Instead, they may forget that their changes
have not been "saved" and they may, for instance, click on a link to take
them to another page.

In this case, I would want to warn them that they have not saved their
changes and keep the user from leaving the page if they don't want to lose
their changes. If I were hand coding this all in HTML and JavaScript then I
would set a "page dirty" type variable via JavaScript when any of the
aforementioned changes to the controls happen, and check that variable
before navigating to another page.

However, depending on how you use them, various asp controls will produce
their own JavaScript code to deal with various situations, such as a
postback when they change. Is there a best practice to deal with this
scenario? If the controls produce their own JavaScript, do I need to
override that functionality? Just looking for some direction here.

Thanks.
 
There is no good practice to do this.

You need to use javascript and hook into the OnUnload event of the document.
You can use Page.RegisterStartupScript and add attributes via
xxx.Attributes.Add() but other than that, there's no silver bullet that I
know of.

Karl
 
Back
Top