Function $ (document) .ready () only executes once

1

I have an Asp.Net application that has a menu on a main screen that has 2 links, each one for a page.

When I click on the first link and load the first page, the $(document).ready() function runs right and loads all the components I need.

When I click on the second link, reviewing Firebug step by step, I notice that the $(document).ready() function is not executed. What is the reason for this?

This application uses a layout page that is rendered before.

Function $(document).ready()

$(document).ready(function () {
    $('#spn').spinit({ min: 1, max: 100, stepInc: 1, pageInc: 10, height: 13, initValue: 95/*,callback: filtraModeloGrafico4*/});

    //Carrega o datepicker
    jQuery('#_InitialDateValue').datetimepicker( { format: 'd/m/Y H:i' } );
    jQuery('#_FinalDateValue').datetimepicker({ format: 'd/m/Y H:i' });

    jQuery('#_InitialDateValue2').datetimepicker({ format: 'd/m/Y H:i' });

    //Carrega a combo com os dias da semana
    $('#idComboTurno').multiselect({
        includeSelectAllOption: true,
        nonSelectedText: 'Select a week day',
        nSelectedText: 'days',
        numberDisplayed: 0
    });

});

The name of the file that has the function $(document).ready() is site.js

This page loads everything right:

@{
    ViewBag.Title = "Sequence Inspection - Graphics Report";
}

@Scripts.Render("~/Scripts/site.js")

<div class="row-fluid">
    <form class="form-inline">
        <div class="control-group span12">
         // Código...
         </div>
    </form>
</div>

Page that does not load the function $(document).ready()

@{
    ViewBag.Title = "Sequence Inspection - Failure Report";
}

@Scripts.Render("~/Scripts/site.js")

<div class="row-fluid">
@using (Html.BeginForm("ExportaExcel", "FailureReport", FormMethod.Post, new { @class = "form-inline" }))
{
  //Código HTML
}
</div>
    
asked by anonymous 29.09.2014 / 20:42

1 answer

1

I do not know if that's the case, but JS inside Partial does not usually run.

Another thing that influences is that you did not specify in which layout block this JS will be loaded. The correct one is to specify @section scripts , which ensures that JS will be loaded at the end of all layout rendering:

@section scripts {
    @Scripts.Render("~/Scripts/site.js")
}
    
30.09.2014 / 00:19