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
159 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 33

Expert Comment

by:ste5an
ID: 40367825
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
ID: 40368079
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
ID: 40368131
Hello Ramkisan Jagtap,
Where would I put this script?.
In the code behind file or an event?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 12

Expert Comment

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

Author Comment

by:MartinChadderton
ID: 40368164
Thank you I'll give it a try
0
 
LVL 1

Author Comment

by:MartinChadderton
ID: 40371008
I'm afraid that didnt work and only showed the script at the top of the page when in the browser.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40371153
Will you please post your code here?
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40371154
Will you please post your code here?
0
 
LVL 1

Author Comment

by:MartinChadderton
ID: 40373333
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
ID: 40373422
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
ID: 40376769
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
ID: 40427843
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
ID: 40434616
There was no workable response from experts.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

823 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