How to use JQuery with Master Pages?

EDIT As @Adam points out in the comments, there is a native jQuery mechanism that basically does the same thing as the hack in my original answer. Using jQuery you can do $(‘[id$=myButton]’).click(function(){ alert(‘button clicked’); }); My hack was originally developed as a Prototype work around for ASP.NET and I adapted it for the original … Read more

Is it possible to share a masterpage between MVC and webforms?

You can absolutely share the same master page. Your MVC master page must simply point to the WebForms masterpage via its MasterPageFile attribute. This applies your WebForms MasterPage styles to your MVC MasterPage. I am using this setup in production. The declaration on my MVC Master Page, pointing at the Web Forms Master Page: <%@ … Read more

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

Parser Error: ‘_Default’ is not allowed here because it does not extend class ‘System.Web.UI.Page’ & MasterType declaration

I figured it out. The problem was that there were still some pages in the project that hadn’t been converted to use “namespaces” as needed in a web application project. I guess I thought that it wouldn’t compile if there were still any of those pages around, but if the page didn’t reference anything from … Read more

Can I dynamically add HTML within a div tag from C# on load event?

You can add a div with runat=”server” to the page: <div runat=”server” id=”myDiv”> </div> and then set its InnerHtml property from the code-behind: myDiv.InnerHtml = “your html here”; If you want to modify the DIV’s contents on the client side, then you can use javascript code similar to this: <script type=”text/javascript”> Sys.Application.add_load(MyLoad); function MyLoad(sender) { … Read more