javascript - how to call jquery function call in asp.net c#? - Stack Overflow

I want to show division for 5 seconds while i do every postback in c#.I am using below function to do t

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" />

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" />
Share edited Oct 18, 2013 at 6:16 Rohan Kumar 40.6k11 gold badges80 silver badges110 bronze badges asked Oct 18, 2013 at 6:06 Vivek ParikhVivek Parikh 6278 gold badges18 silver badges32 bronze badges 14
  • are you already included the jquery script dependency? – Olrac 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 – iJade Commented Oct 18, 2013 at 6:12
  • Try to show division before postback on client using javascript. – Frank59 Commented Oct 18, 2013 at 6:12
  • post the html code too – iJade Commented Oct 18, 2013 at 6:14
  • @Frank59 not working.... – Vivek Parikh Commented Oct 18, 2013 at 6:25
 |  Show 9 more ments

3 Answers 3

Reset to default 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

You already hiding the image in document.ready function

<script>
    $(document).ready(function () {
        //$('#correct').hide(); // remove this line or ment 
        // 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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744861948a4597754.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信