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
163 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 34

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to count occurrences of each item in an array.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

717 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