title: Callback timing issue in javascript when passed through view in asp mvc
body: <p>I have a feeling this is a simple issue I'm missing but after a couple of hours I've given up and decided to post in here.</p>
  
  <p>I'm trying to implement a generic paging partial view that I can use across the entire site. As a result the paging model takes a function that will be bound to the paging controls that is used as a callback at a later time. See UpdateFunction below.</p>
  
  <pre><code>ViewModels.Shared._PaginationPartialViewModel pagination =
              new ViewModels.Shared._PaginationPartialViewModel()
              {
                  CurrentPage = Filter.Page,
                  ItemFrom = GenericHelpers.Paging_GetItemFrom(10, Filter.Page, TotalItems),
                  ItemTo = GenericHelpers.Paging_GetItemTo(10, Filter.Page, TotalItems),
                  TotalItems = TotalItems,
                  TableClass = Filter.Table,
                  TotalPages = (int)Math.Ceiling((double) TotalItems / 10),
          UpdateFunction = "getTransfers('" + Filter.Table + "')"
              };
  </code></pre>
  
  <p>Now when the model is bound to the view, this function is passed in as a callback to a javascript click event paginationClick() like so...</p>
  
  <pre><code>&lt;a href="#" class="stock-pagination__action stock-pagination__action_state_active @(Model.TableClass + "_Page")" data-page="@Model.CurrentPage" onclick="paginationClick(this, @(Model.CurrentPage), @Model.UpdateFunction); return false;"&gt;@Model.CurrentPage&lt;/a&gt;
  </code></pre>
  
  <p>The paginationClick() function fires, but when checking the dev console the callback method appears to be firing first. Here's the paginationClick() method... (I know that the page parameter is not currently being utilized btw!)</p>
  
  <pre><code>function paginationClick(control, page, callback)
  {
  if (!$(control).hasClass('stock-pagination__action_state_active')) {
      $(control).parent().find('a').each(function () {
          $(this).removeClass('stock-pagination__action_state_active');
      });
  
      $(control).addClass('stock-pagination__action_state_active');
  
      callback;
  }   
  </code></pre>
  
  <p>}</p>
  
  <p>I anyone can offer an extra pair of eyes it would be much appreciated!</p>