asp.net c# updatepanel asyncpostback javascript function

Viewed 39

My javascript code below is running when the page is loaded. Updatepanel doesn't work when there is asyncpostback. I have tried many ways but without success.

HTML

<a onclick="direkyok()">MenĂ¼</a>

Javascript:

<script> 
  $(document).ready(function direkyok() {  
          $("body").toggleClass("mini-navbar mini-body"); 
  }); 

C# Page Load

ScriptManager.RegisterStartupScript(this, typeof(Page), 
                                                  "direkyok", "direkyok();", true);
1 Answers

The JavaScript function is only defined in the scope of the parameter of $(document).ready. You should make it accessible for the script manager by placing it somewhere else, e.g.:

<script> 
    //"globally" accessible
    function direkyok() {  
          $("body").toggleClass("mini-navbar mini-body"); 
    }  

    $(document).ready(/* other stuff*/);
</script>
Related