How to add master page to already created webform? - asp.net

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.

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..

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)

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

ASP.NET Master Page not updating Child Page

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.

How to identify content page loads in a master page dynamically?

I have a master page 'Master1' and i have used a content place holder 'content1' and loads
pages 'Page1' and 'page2' in the 'content1'. Is there any way to identify which page is loaded to the content place holder whether it is 'Page1' or 'Page2' dynamically.
I think maybe you have misunderstood how master pages work?
In you master page you define the guts of your page that you want all pages to share, like headers and footers etc. The you define a content holder:
<asp:ContentPlaceHolder runat="Server" ID="MainContent">
</asp:ContentPlaceHolder>
The contents of Page1.aspx etc will be injected into that ContentPlaceHolder.
Then in your aspx pages you simply define which master page it should use:
<%# Page Language="C#" MasterPageFile="~/MyMasterPage.Master" ... />
and then define the content that should be injected in to the place holder in the master:
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
put all your html in here
</asp:Content>
Note the id used for the ContentPlaceHolderID property, so that it gets injected into the right place - the master page could have several place holders. So both Page1.aspx and Page2.aspx can be loaded in to the place holder, all you have to do is navigate to whichever page you want to display. Nothing needs to be done on the master page.
Try this
ViewContext.RouteData.GetRequiredString("action")

Resources