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
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
160 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.

809 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