Skip to content Skip to sidebar Skip to footer

How To Call Jquery Function Call In Asp.net C#?

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.ClientScri

Solution 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


Solution 2:

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


Solution 3:

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


Post a Comment for "How To Call Jquery Function Call In Asp.net C#?"