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
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making exceptions for ValidationAttribute 2 27
Header Font Size in Grid View 6 27
Web page design problem 3 18
HTML CSS and  Table design 4 15
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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