how to call jquery function call in asp.net c#?

14,065

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

Share:
14,065
Vivek Parikh
Author by

Vivek Parikh

Updated on June 11, 2022

Comments

  • Vivek Parikh
    Vivek Parikh almost 2 years

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