ASP.NET MVC RC2 template head after body? - asp.net

When I installed ASP.NET MVC RC2, I noticed that the template had changed from RC1. Now, all new views have the header placeholder after the main content place holder. Why is this? It seems very illogical to me and it most definitely was not the case with RC1. I googled but couldn't find any reasoning for this change. Do you know of any?
Example:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Rules</h2>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
Note how the placeholder with ContentPlaceHolderID of "head" is at the bottom? Weird...

I can't say I noticed it when I upgraded, but it shouldn't matter. The two <asp:Content> sections get mapped by the ID property to their places as defined in Site.master.
Definitely check the order in Site.master, but it should be fine.
If you want to change this, you can look into the T4 template your views are using. Check out:
t4-templates-in-asp.net-mvc
t4-templates-a-quick-start-guide-for-asp-net-mvc-developers
overriding-global-t4-templates-in-asp-net-mvc-project-with-per-project-templates

Related

Is there any possibility to add master page for more then one existing .aspx page?

I already made update.aspx page and view.aspx page now I want to assign master page that to these pages...can someone help me out ?
Create new master page names Site.Master, move everything you want from update.aspx into master, so probably Head section html content, and then in the body put the placeholder:
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
Now when "shared" master content is moved from your update.aspx/view.aspx, you just need to wrap everything that's left in those pages into this:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
your update.aspx page content
</asp:Content>
In first line of your page you should have something like <%# Page ... attributes ... %>, add new attribute that points to the master page: MasterPageFile="~/Site.Master"
For the reference, create new WebForms project and you'll get few sample pages. See how should a HTML content in the master page look like, and how to wrap page content of you aspx page.
End result should look something like this:
Site.Master
<html><head>...</head>
<body>
some master body html content
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
more html here
</body>
<html>
Then the page:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
your update.aspx page content
</asp:Content>
i suppose your master page is Main.Master
the first step
in the update.aspx page and view.aspx page (at the top )
make MasterPageFile attribute = "~/Main.Master" this is the code
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="update.aspx.cs"
the second step
remove the head and title and body and html tags from the update.aspx page and view.aspx page
and put tow content two content place holders (the same in the master page) in your pages(update.aspx and view.aspx)
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
the previous content place holder represents the head of this page you can put in it any css or java script code or references
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"></asp:Content>
second placeholder represents the body of this page you can put in it the body of your page(update.aspx)

Use UserControl or WebForm?

In my home page I have 3 sections; Services, About and Portfolio.
I want to separate the HTML/code for each of these sections into their own files (WebForms/UserControls) so I can reuse these on other pages.
In ASP.NET WebForms; is the correct way to construct these sections as UserControls or WebForms with no master file?
As I understand a UserControl is more for a custom widget/tag such as a custom GridView or something. So maybe UserControls wouldn't suit this?
Eg;
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="My._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
// Include About
// Include Services
// Include Portfolio
</asp:Content>
In case you are going to reuse the sections across the web site I'd go with UserControls. It's more versatile. If you'd put the code to web forms you'd be dependent on the masterpage's ContentPlaceHolder.

Error on Adding Master Page.

I have a using ASP.net C# firstly I have created a webform FrmFirst.aspx. Then I have created a master page. Now I have to add my first page to master page then I am facing the same error :
I am using this code to add my first page to Master page
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="FrmCustomerMaster.aspx.cs" Inherits="FrmCustomerMaster" %>
Tell me my Problem !! Thanks ....
You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders
see LINK
if your master page contain this code
<asp:contentplaceholder id="Main" runat="server" />
your page that Inherits from master should have
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
</asp:Content>

ASP.NET Ajax Accordion Control not working properly with ScriptManager

I've been reading SO for a while now, but that's the first time I post a question (first time I don't find the answer of what I'm looking for)
Here is my setup:
Master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Master.master.cs" Inherits="VatechWebsite.Master" %>
<html>
<head>...</head>
<body>
<form>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
...
<asp:ContentPlaceHolder ID="content" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
Content page:
<%# Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Brand.aspx.cs" Inherits="VatechWebsite.Brand1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
<asp:Accordion ID="CategoriesAccordion" runat="server" HeaderCssClass="AccordionHeader">
<HeaderTemplate><%# DataBinder.Eval(Container.DataItem, "CategoryName") %></HeaderTemplate>
<ContentTemplate>
<div id="ProductList">Some text<br />supposed to be very large <br/></div>
</ContentTemplate>
</asp:Accordion>
<asp:Content/>
When I run this page, the accordion displays correctly, binds data correctly, and has the first pane expanded. The problem is, I cannot expand/collapse a pane. It seems that the javascript associated with this control is not running correctly. If I replace ScriptManager in the master page with a ToolkitScriptManager, the problem is solved; but I don't want to do that because I have other pages that need the ScriptManager.
I read that the ScriptManager should be adequate for running asp ajax controls, so why is it not working in this case?
If you're stuck with one ScriptManager for some pages, and ToolKitScriptManager for another, there are ways to use the same master page on all your pages, and use different ScriptManager on different pages.
This answer details a few approaches, one approach will disable Master.ShowScriptManager = false; on PageLoad.
Disable ScriptManager on certain pages
Another suggests having different ScriptManagers on for different ContentPlaceHolders, which also works.
Hope this helps!

Master Page Error on New MVC Project

I've just create a new MVC project, and have made no changes at all, but when I try and view the ChangePasswordSuccess view in design mode, I get the error:
The page has controls that require a Master Page reference, but none is supplied.
The page has no controls except for a content control and literal text, and it does have a master page reference. Anyone know what's up?
<%#Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="ChangePasswordSuccess.aspx.cs" Inherits="BasicMvcApp.Views.Account.ChangePasswordSuccess" %>
<asp:Content ID="changePasswordSuccessContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>Change Password</h2>
<p>
Your password has been changed successfully.
</p>
</asp:Content>
No sooner asked than noticed. The default ChangePasswordSuccess view's Page directive is missing the word Page.

Resources