Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:01:52+00:00 2026-06-12T06:01:52+00:00

jQuery noob here: I have the following message div that shows a message on

  • 0

jQuery noob here:

I have the following message div that shows a message on button click and fades after several seconds. This works fine. However, I would like the message div to hide on page load and display on button click.

So far, I’ve tried adding the hideDiv class to the message div, but then messageDiv doesn’t display at all (on load or on button click). I’ve also tried hiding/showing a parent wrapping Div (not shown here).

Suggestions?

<div id="messageDiv" runat="server" class="alert">Row Deleted</div>

.

<style type="text/css">
.alert{display:block;width:100%;color:#900000;font-size: 1.4em;}
.hideDiv{display:none;}
</style>

.

<script type="text/javascript">
$(document).ready(function () {
$(document.getElementById('<%= messageDiv.ClientID %>')).addClass("alert"); setTimeout(function () {
$(document.getElementById('<%= messageDiv.ClientID %>')).fadeOut("slow", function () {
$(document.getElementById('<%= messageDiv.ClientID %>')).remove();
});
}, 4000);
});
</script>

.

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 

protected void Button1_Click(object sender, EventArgs e)
{messageDiv.InnerText = "Row Action Completed";}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:01:53+00:00Added an answer on June 12, 2026 at 6:01 am

    So I worked out my own solution. I’m sure there’s a more concise solution out there (and I’d be glad to hear it), but I ended up with the following parts:

    Solution:

    • The message div must be hidden (display:none) on page load.
    • I set a page level server-side var to false, to indicate the message should not be shown yet (per solution here)
    • Set that var to true in server-side button click event
    • Check for var = true in jQuery before calling the code to show/fade the Div
    • Remove the existing hidden class from the messageDiv before adding the alert class and fade effects.

    So all the working parts:

    Server-side script:

    <script type="text/C#" runat="server">
        Boolean UserHasClicked = false;
        protected void Button1_Click(object sender, EventArgs e)
        {
            UserHasClicked = true;
            messageDiv.InnerText = "Row deleted successfully.";
        }
    </script>
    

    .

    Client-side script:

    <script type="text/javascript">
    var userHasClicked = '<%= this.UserHasClicked %>' == 'True'
    $(document).ready(function () {
    if (userHasClicked) {
    $(document.getElementById('<%= messageDiv.ClientID %>')).removeClass("hideDiv");
    $(document.getElementById('<%= messageDiv.ClientID %>')).addClass("alert");
    $(document.getElementById('<%= messageDiv.ClientID %>')).delay(4000).fadeOut("slow");      
    }
    });
    </script>
    

    This was an interesting exercise, but I’m sure that there’s a more polished control or solution for showing/fading messages in .net out there somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery noob here. I have a jQuery handler that makes use of $(this) .
I'm a noob in jQuery and have stuck at this. I have the following
noob here i got this jquery code that i found on stackoverflow var maxLines
I want to have a div that animates the currently active image out of
I'm just learning jQuery, I'm so noob. see, we have 2 divs as follows:
I have a function that calls jQuery's pulse function. I use it on a
(jQuery noob here) Im trying to write a script which when I write <input
I'm a complete noob to JQUERY, learning things slowly. But I have been downloaded
I'm a jQuery noob here, please help! Much much appreciated! my urls.py: url('^xhr_test/$','posts.views.xhr_test'), my
Jquery wont load. I'm a noob, but have persisted, trawled this site & tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.