ASP.NET Master Page not updating Child Page - asp.net

I have made a site that is based off of a MasterPage and after creating a few pages I added a new <asp:ContentPlaceHolder> but it seems the existing pages wont update to include it, however new pages do.
Is there a way to force an update, or is there a proper way to do this? I just saved the Master Page and hoped for the best.

You need to add the new <asp:ContentPlaceHolder> to your old aspx pages manually.
in your master page:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="new_one" runat="server"></asp:ContentPlaceHolder>
in your old aspx pages, add:
<asp:Content ID="Content3" ContentPlaceHolderID="new_one" runat="server">
</asp:Content>

If you create a new content placeholder in your master page, your content pages don't NEED to have a corresponding <asp:Content>. They only need one if you want to replace the default content placed in the master page.
And if you're going to update each page with its own content, then adding the <asp:Content> tags is likely a relatively small inconvenience.
Unfortunately there is not a way for Visual Studio to search out all your content pages and update them with new <asp:Content> controls.
However, you could do it fairly quickly by finding using the id of an existing <asp:Content> control, and do a ctrl+shift+F and replace with your new <asp:Content> plus what you searched for.
For example, if your content pages already all had a
<asp:Content ID="Content3" ContentPlaceHolderID="old_one" ... />
then you could search for that and replace with
<asp:Content ID="Content4" ContentPlaceHolderID="new_one" runat="server" /><asp:Content ID="Content3" ContentPlaceHolderID="old_one" ... />
Not exactly pretty, but it could save some time.

Related

Can't add content on pages using webform template in Umbraco

I am using umbraco 7 and i'm not really good on MVC, so i am using webforms and when i try to use a webform template i can't add content on the page, just on the template.
Here i use in de default.master file the contentplace holder like this:
<div id="mainContent">
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
Then i create the template called "Text Webform" and this is the code:
<%# Master Language="C#" MasterPageFile="~/umbraco/Masterpages/Default.master" AutoEventWireup="true" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
This content is displayed
Am i forgetting some code to add here?
</asp:Content>
Click on this to see screenshot
The problem is when i try to add content in a page that is using "Text Webform" template, that content is not displayed, as you can see on the screenshots here
I'm sure i need to add some content in the Text Webform template but i don't know exactly what and i'm desperate, please somebody provide any help,
Thanks.
You have to define what fields (eg properties from your document type) to show where in your template. I believe this is what you are looking for? https://our.umbraco.org/documentation/Reference/Templating/Masterpages/umbracoitem - just
Ok, now i can explain it better,
I just want the equal function to #CurrentPage.GetGridHtml("content", "fanoe") using a webform template..

Form tag inside master page and content page

I have one master page and several content pages , I need to put a form tag inside a master page to handle sending data from my html elements and do this for my content pages as well .but I need to understand what is the best way to structure for such this scenario and what would be the effect of form tag of master page on content pages ? is it possible to put form tag in content pages when the master page has this tag inside itself ? I appreciate if I have in detail explanation ?
The <form runat="server"> element lives in the master page by default when you add a new one to your project; all child pages are implemented using ContentPlaceHolders.
For example, the master page: -
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
You can have as many ContentPlaceHolders as you need (often only one is needed though). If you then add a "child page using master page", the page-specific content is added inside the relevant <asp:Content> element - these are added by default once you have specified the master page to use when adding a "child page using master page": -
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<!-- your markup, controls etc.. -->
</asp:Content>
Have a read of the MSDN docs for more - http://msdn.microsoft.com/en-us/library/aa581781.aspx

How to add master page to already created webform?

I have a asp.net webform application. Now I have to add master page in this application, but I don’t know how to merge or add new created master page with old webforms? How to handle html in webforms like <head> , <body> ? Any link in this regard will be helpful.
1- Define the fixed elements in your design, and put them inside the newly created master page
2- Define the dynamic ones, and add asp:ContentPlaceHolder for them ( most commonly one for HEAD, one for main content in your BODY , and one for side content "if applicable")
<asp:ContentPlaceHolder ID="CphHead" runat="server">
</asp:ContentPlaceHolder>
3- In your pages, add MasterPageFile="~/MASTER_PAGE_PATH" inside the Page directive.
4- Add asp:Content sections inside your pages which will hold the dynamic content in your pages, and don't forget to reference the correct ContentPlaceholder ID.
<asp:Content ID="HeadContent" ContentPlaceHolderID="CphHead" runat="server">
// Your content goes here...
</asp:Content>
5- Copy your page content inside these asp:content sections, and BOOOOM....you are done.
at the top of the new page in the '<%# page #>' tag add 'MasterPageFile="~/Site.Master"'
then add the needed placeholders
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
of course modify these to the names you are using
you can add the content holder tag in master page. So when you add 'MasterPageFile="~/Site.Master"' then you able to add content of other pages.

Resources regarding sidebar in master page

I'm new to .net master pages. I want to have a simple sidebar with 4 links where the user is just redirected to those .aspx pages.
How can i start with this ?
If it is too dumb question to answer ;) atleast give me the good resources/links/tutorials online so that i can go through and accomplish this task.
The moderator/some one who doesn't like this question may delete this after getting answered. Please don't down vote or flag this.
BTW i'm using visual studio 2008, asp.net/C#
Thanks in anticipation
I think you shouldn't worry about someone deleting your question(s)? Anyone deserves help, and for your problem:
First you create the masterpage, then when you create a page, say you want to select a masterpage, and select the one you just created.
Inside of a masterpage you have contentplaceholders, which will also show up in all the other pages you create and 'connect' to that masterpage, which will contain the content that is on any page, for example: your default.aspx has 'Hello people, welcome', on the default.aspx, you put it inside of a contentplaceholder and then it gets loaded.
So what happens basically is: Your masterpage gets loaded, with inside of the contentplaceholder the content of the page. Meaning that anything you put outside of the contentplaceholder, in the masterpage, will get loaded as well, everytime a page is connected to that masterpage.
Edit:
Here is a snippet of how i used it:
Masterpage snippet:
<%# Register TagPrefix="UserControl" TagName="AccountMenu" Src="~/Controls/AccountMenu.ascx" %>
<UserControl:AccountMenu runat="server" ID="AccountMenu" />
<div id="content" style="background-color:#f5e29d; width:461px; margin: -10px 0 -10px 0; padding:10px 0 10px 0;">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
Page snippet:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
Hello people, welcome!
</asp:Content>
I then have a folder called 'Controls', and in there a UserControl called 'AccountMenu' with the following in it:
Accountmenu snippet:
<table>
<tr>
<td>Create account</td>
</tr>
</table>
I always believed this was quite a nice way to do it, but maybe use <ul> and <li>'s instead of a table ^^,
Lauw
If it is only a sidebar, you could consider making it a user control and put it on the pages where you need it.

ASP.NET page content - where does this belong?

I am working on a web application that has a single master page and several content pages. Each page will have a small sidebar to the right of the main content with some brief content. However, that brief content is specific to the page you are on. I can't decide whether to put that on each individual page, or in the master page in a MultiView with some logic in code-behind to specify which view is shown based on which page you are on.
Which seems more elegant? I'm still fairly new with ASP.NET and I'm trying to get a good feel for proper architecture, etc.
You can create multiple content placeholders in a single masterpage. So in your case I would create two. One for the article's content and one for the sidebar like:
<!-- some html-->
<asp:contentplaceholder id="ArticleContents" runat="server">
</asp:contentplaceholder>
<!-- some more html-->
<asp:contentplaceholder id="ArticleSidebar" runat="server">
</asp:contentplaceholder>
<!-- even more html-->
then you could have the article contents and the sidebar contents both in the same page and place it in the correct spot using something like
<asp:Content ID="article" ContentPlaceHolderID="ArticleContents" Runat="Server">
Your article
</asp:Content>
<asp:Content ID="sidebar" ContentPlaceHolderID="ArticleSidebar" Runat="Server">
Your sidebar
</asp:Content>
If you want some manageability in the case of your site getting larger and needing more of these custom sidebars then I would not put anything beyond standard layout in the master page.
What is wrong with having an additional ContentPlaceHolder in the side bar and just adding the content into Content controls on each content page?
Your approach seems overly complex to me.
You could also put that additional code into a user control (or two). The content page would then include the user control appropriate to that page for the right sidebar.

Resources