PageDirty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anithaapr05
    New Member
    • Aug 2009
    • 11

    #1

    PageDirty

    Dear All

    I have a page which has different editable usercontrols on it. All of these controls let user proivide data. My page has several usercontrols that are editable. In the edit mode, when the user changes state on the control, that page is set to dirty.The user try to navigate with out save,i need the the message the page is dirty.I am having the infragistics controls in my page.
    how to do this.


    Thanks
    Anitha
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You will have to use JavaScript to do this.

    The OnBeforeUnload Event is a neat feature used by web developers to let the user cancel the page submit if they need to.

    What you'll have to do is add a HiddenField to the page indicating whether or not the page is dirty.

    Write a JavaScript function that will handle the OnBeforeUnload JavaScript event. This function will check the HiddenField, and if the page is dirty will return "You have unsaved changes. Are you sure you want to leave the page?".

    The only thing is that this event will fire every time the page is unloaded.
    So you'll also need to write a bit of JavaScript that determines whether or not to display the message depending on if the page is posting back for reasons other than leaving current page.


    Note: that the onbeforeunload event happens when the whole page is being unloaded....thi s means that if you're using Ajax this event will not fire.

    If you just want to check if the page is dirty when the user clicks on some control that leads the user away from your page then you could just call the function that checks if the page is dirty during the OnClick (or onChange) event (client side) for the control.

    If you want to inform the user that they will lose information if they are leaving the page by hitting the back button, or typing a new url ...etc...then use the OnBeforeUnload event.

    -Frinny

    Comment

    Working...