Proper way to use JQuery when using MasterPages in ASP.NET?

You would declare your main jQuery scripts within the master page, as you would normally: <head runat=”server”> <link href=”https://stackoverflow.com/Content/Interlude.css” rel=”Stylesheet” type=”text/css” /> <script type=”text/javascript” src=”/Scripts/jquery-1.3.2.min.js”></script> <asp:ContentPlaceHolder ID=”head” runat=”server”> </asp:ContentPlaceHolder> </head> And then any page specific JS files could be loaded within the Content controls that reference the Head ContentPlaceholder. However, a better option would be … Read more

active menu item – asp.net mvc3 master page

A custom HTML helper usually does the job fine: public static MvcHtmlString MenuLink( this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName ) { string currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString(“action”); string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString(“controller”); if (actionName == currentAction && controllerName == currentController) { return htmlHelper.ActionLink( linkText, actionName, controllerName, null, new { @class = “current” }); } return … Read more

Hook a javascript event to page load

If you don’t want to explicitly assign window.onload or use a framework, consider: <script type=”text/javascript”> function startClock(){ //do onload work } if(window.addEventListener) { window.addEventListener(‘load’,startClock,false); //W3C } else { window.attachEvent(‘onload’,startClock); //IE } </script> http://www.quirksmode.org/js/events_advanced.html

how to access master page control from content page

In the MasterPage.cs file add the property of Label like this: public string ErrorMessage { get { return lblMessage.Text; } set { lblMessage.Text = value; } } On your aspx page, just below the Page Directive add this: <%@ Page Title=”” Language=”C#” MasterPageFile=”Master Path Name”….. %> <%@ MasterType VirtualPath=”Master Path Name” %> // Add this … Read more