2

I would like to show a message on my ASP.Net page like "Record saved" on save button click. After 5 seconds, I would like to hide it.
How can I do in JavaScript? Can I avoid to add jQuery (I'm not using it)?

Himanshu Jansari
  • 30,115
  • 28
  • 106
  • 129
stighy
  • 7,595
  • 22
  • 89
  • 150

3 Answers3

9

You could use the setTimeout function which allows you to defer the execution of a callback in the future. So you could place the following in the page:

<script type="text/javascript">
    window.setTimeout(function() {
        // This will execute 5 seconds later
        var label = document.getElementById('IdOfTheElementYouWantToHide');
        if (label != null) {
            label.style.display = 'none';
        }
    }, 5000);
</script>

Due to ID name mangling with ASP.NET you could use a class selector. And once you start doing this and your users start to ask you about adding some fade out effects you will quickly realize that a framework such as jQuery might come in handy.

Community
  • 1
  • 1
Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
3

You can use a JavaScript notification plugin Pines Notify

Look at that link to more choices

Community
  • 1
  • 1
Anyname Donotcare
  • 10,649
  • 59
  • 212
  • 375
1

You can use the jGrowl add-in for jQuery - this provides "Mac-style" notifications for this kind of scenario.

cjk
  • 44,524
  • 9
  • 79
  • 111