Friday, 19 October 2012

ASP.NET MasterPage: How to add jQuery/JavaScript function in ASP.NET Master Page

Scenario:
I added javascript.js file and created a function. I could not call the function writing the same code of html. Calling a javascript from a asp.net master page is different.

Solution:
In order to add any javascript function inside a asp.net page with master page you have to insert the function inside -->Head section-->then content

<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %> - My ASP.NET Application</title>

    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
        <script type="text/javascript" src="Scripts/JavaScript-local.js"></script>
        <script type="text/javascript">
             changeMenuColor();
        </script>
    </asp:PlaceHolder>

</head>

No comments:

Post a Comment