Solved

How do i warn user that data has been changed in a vb.net web form before they close the form by selecting a hyperlink?

Posted on 2014-10-07
16
155 Views
Last Modified: 2014-11-11
y vb.net web application uses hyperlinks to navigate between pages.
When a user navigates between pages the data changed on a web form is then lost if they have not pressed the update button prior to navigating to the next page. i want to warn the users if data (usually textboxes) have been changed and they have not clciked the update button before the navigation to the next page.
I check for ispostback on the page and if not it refreshes the data from the last saved in the database.
0
Comment
Question by:MartinChadderton
  • 7
  • 5
16 Comments
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
It depends on your architecture. But normally this is handled in the browser with an appropriate JavaScript.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
Comment Utility
Please check the following script:
var warnMessage = "You have unsaved changes on this page!";

$(document).ready(function() {
    $('input:not(:button,:submit),textarea,select').change(function () {
        window.onbeforeunload = function () {
            if (warnMessage != null) return warnMessage;
        }
    });
    $('input:submit').click(function(e) {
        warnMessage = null;
    });
});
0
 
LVL 1

Author Comment

by:MartinChadderton
Comment Utility
Hello Ramkisan Jagtap,
Where would I put this script?.
In the code behind file or an event?
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
Comment Utility
You have to put this script on aspx page. Preferably in the <head></head> section.
0
 
LVL 1

Author Comment

by:MartinChadderton
Comment Utility
Thank you I'll give it a try
0
 
LVL 1

Author Comment

by:MartinChadderton
Comment Utility
I'm afraid that didnt work and only showed the script at the top of the page when in the browser.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:Ramkisan Jagtap
Comment Utility
Will you please post your code here?
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
Comment Utility
Will you please post your code here?
0
 
LVL 1

Author Comment

by:MartinChadderton
Comment Utility
Im using a Master template :

<head runat="server">
    <title>TRANSFORMATION</title>
    <link type="text/css" href="../StyleSheet/StyleSheet.css" media="screen" rel="stylesheet" />
    <link type="text/css" href="../StyleSheet/GridStyleSheet.css" media="screen" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../StyleSheet/superfish.css" media="screen">
   <link rel="stylesheet" type="text/css" href="../StyleSheet/TextBox_Focus.css" media="screen" />
    <script src="js/TextBox_Focus.js" type="text/javascript" language="javascript"></script>  

 
var warnMessage = "You have unsaved changes on this page!";

$(document).ready(function() {
    $('input:not(:button,:submit),textarea,select').change(function () {
        window.onbeforeunload = function () {
            if (warnMessage != null) return warnMessage;
        }
    });
    $('input:submit').click(function(e) {
        warnMessage = null;
    });
});

   
</head>
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
Comment Utility
Change it like below:

<head runat="server">
    <title>TRANSFORMATION</title>
    <link type="text/css" href="../StyleSheet/StyleSheet.css" media="screen" rel="stylesheet" />
    <link type="text/css" href="../StyleSheet/GridStyleSheet.css" media="screen" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../StyleSheet/superfish.css" media="screen">
   <link rel="stylesheet" type="text/css" href="../StyleSheet/TextBox_Focus.css" media="screen" />
    <script src="js/TextBox_Focus.js" type="text/javascript" language="javascript"></script>  

  <script type="text/javascript" language="javascript">
  var warnMessage = "You have unsaved changes on this page!";

$(document).ready(function() {
    $('input:not(:button,:submit),textarea,select').change(function () {
        window.onbeforeunload = function () {
            if (warnMessage != null) return warnMessage;
        }
    });
    $('input:submit').click(function(e) {
        warnMessage = null;
    });
}); 
</script>    
</head>

Open in new window

0
 
LVL 1

Author Comment

by:MartinChadderton
Comment Utility
Changed it to the below but it does not produce message when user changes value and then uses link to navigate off page. This is in the master file which other pages inherit from; does that make a difference?

<title>TRANSFORMATION</title>
    <link type="text/css" href="../StyleSheet/StyleSheet.css" media="screen" rel="stylesheet" />
    <link type="text/css" href="../StyleSheet/GridStyleSheet.css" media="screen" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../StyleSheet/superfish.css" media="screen">
   <link rel="stylesheet" type="text/css" href="../StyleSheet/TextBox_Focus.css" media="screen" />
    <script src="js/TextBox_Focus.js" type="text/javascript" language="javascript"></script>
   
    <script type="text/javascript" language="javascript">
      var warnMessage = "You have unsaved changes on this page!";

    $(document).ready(function() {
    $('input:not(:button,:submit),textarea,select').change(function () {
        window.onbeforeunload = function () {
            if (warnMessage != null) return warnMessage;
        }
    });
    $('input:submit').click(function(e) {
        warnMessage = null;
    });
    });
</script>    

       
</head>
0
 
LVL 1

Accepted Solution

by:
MartinChadderton earned 0 total points
Comment Utility
Ok, I've eventually solved this problem myself by looking at other on line forums and piecing together a solution.
Basically I created an isdirty flag when something has changed then checking for that when a link is pressed.
0
 
LVL 1

Author Closing Comment

by:MartinChadderton
Comment Utility
There was no workable response from experts.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now