title: Running code on page loaded?
body: <p>I have a MVC view that contains some dropdowns like this : </p>
  
  <pre><code>        &lt;%: Html.DropDownListFor(model =&gt; model.CS.C1, Model.CS.Category1List, "-- Välj kategori --")%&gt;
          &lt;%: Html.DropDownListFor(model =&gt; model.CS.C2, Model.CS.Category2List, "-- Välj kategori --")%&gt;
          &lt;%: Html.DropDownListFor(model =&gt; model.CS.C3, Model.CS.Category3List, "-- Välj kategori --")%&gt;
          &lt;%: Html.DropDownListFor(model =&gt; model.CS.C4, Model.CS.Category4List, "-- Välj kategori --")%&gt;
          &lt;%: Html.DropDownListFor(model =&gt; model.CS.C5, Model.CS.Category5List, "-- Välj kategori --")%&gt;
          &lt;%: Html.DropDownListFor(model =&gt; model.CS.C6, Model.CS.Category6List, "-- Välj kategori --")%&gt;
  </code></pre>
  
  <p>To compliment this with AJAX calls (to create CascadingDropDown) I have the following javascript : </p>
  
  <pre><code>$(document).ready(function () {
  
              $("#CS_C1").change(function () { lastCategoryId = $("#CS_C1").val() });
              $("#CS_C2").change(function () { lastCategoryId = $("#CS_C2").val() });
              $("#CS_C3").change(function () { lastCategoryId = $("#CS_C3").val() });
              $("#CS_C4").change(function () { lastCategoryId = $("#CS_C4").val() });
              $("#CS_C5").change(function () { lastCategoryId = $("#CS_C5").val() });
              $("#CS_C6").change(function () { lastCategoryId = $("#CS_C6").val() });
  
              $("#CS_C2").CascadingDropDownCategory("#CS_C1", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
              $("#CS_C3").CascadingDropDownCategory("#CS_C2", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
              $("#CS_C4").CascadingDropDownCategory("#CS_C3", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
              $("#CS_C5").CascadingDropDownCategory("#CS_C4", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
              $("#CS_C6").CascadingDropDownCategory("#CS_C5", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
  
              $("#LS_L2").CascadingDropDown("#LS_L1", '/Location/GetLocationsByParent', '', true);
  
              alert(lastCategoryId);
              SetFilter(lastCategoryId);
          });
  </code></pre>
  
  <p>The CascadingDropDownCategory function is from <a href="http://weblogs.asp.net/rajbk/archive/2010/05/20/cascadingdropdown-jquery-plugin-for-asp-net-mvc.aspx" rel="nofollow">this site</a>.</p>
  
  <p>When doing a post the dropdowns is set properply but when running </p>
  
  <pre><code>SetFilter(lastCategoryId);
  </code></pre>
  
  <p>The lastCategoryId is sill -1? I can see that the dropdowns have got values and should also have triggered the change event? Why is i getting -1? How could I solve it?</p>
  
  <p>BestRegards</p>