2

I want to show division for 5 seconds while i do every postback in c#.I am using below function to do that but it doesn't work.

I used this code on page load in c#.

Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);

in aspx page

<script type='text/javascript' src='Scripts/scripts/jquery.min.js'></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#correct').hide();

    });
</script>

<img alt="" id="correct" src="Que-img/correct.png" />
14
  • are you already included the jquery script dependency? Commented Oct 18, 2013 at 6:12
  • works well and good for me.Can post what is "correct" and double check if u have jQuery included in page Commented Oct 18, 2013 at 6:12
  • Try to show division before postback on client using javascript. Commented Oct 18, 2013 at 6:12
  • post the html code too Commented Oct 18, 2013 at 6:14
  • @Frank59 not working.... Commented Oct 18, 2013 at 6:25

3 Answers 3

1

use

    RegisterClientScriptBlock(Page.GetType(), "PostbackClick", "$(document).ready(function(){
setTimeout(function() { $('#correct').fadeIn(1500); }, 5000)});", true)

Because you have to wait for JQuery.ready before using jquery selectors. RegisterStartupScript actually happens before jquery ready. in my answer your setTimer will executed on jquery ready

Sign up to request clarification or add additional context in comments.

Comments

0

You already hiding the image in document.ready function

<script>
    $(document).ready(function () {
        //$('#correct').hide(); // remove this line or comment 
        // because fadeOut will work on visible elements

       function hideImage() {
           setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
       };
    });
</script>

In C#

Page.ClientScript.RegisterStartupScript(Page.GetType(),"PostbackClick", "script",
                                        "hideImage();" true);

How to Call Jquery from C# will help you

2 Comments

actually i want image to be disappear after 5 seconds.
not working..Btw i want to show image for 5 sec after postpack click.
0

I guess i got your issue ...Modify your code as below

$(document).ready(function () {
     $('#correct').hide();
    $('#btnId').click(function(){
          $('#correct').show();
          setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
    });
});

and remove

Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);

Here is the demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.