Can't add content on pages using webform template in Umbraco - asp.net

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

Related

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 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 MVC - View with master page, how to set title?

What is prefered way of setting html title (in head) for view when using master pages?
One way is by using Page.Title in .aspx file, but that requires in master page which can mess with HTML code. So, lets assume no server side controls, only pure html. Any better ideas?
UPDATE: I would like to set title in view NOT in the controller or model.
In our master pages, we created both an "init" ContentPlaceHolder, and a "title" ContentPlaceHolder. If someone wants to programatically set Page.Title, they can set it in CSharp in the init placeholder, or they can override the "title" placeholder using tags.
Master Page
<asp:ContentPlaceHolder id="init" runat="server"></asp:ContentPlaceHolder>
<head runat="server">
<asp:ContentPlaceHolder ID="title" runat="server">
<title><%=this.Page.Title%></title>
</asp:ContentPlaceHolder>
</head>
View Page
Could either override the entire "title" content placeholder:
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
<title>Home Page</title>
</asp:Content>
or programatically set the page title.
<asp:Content ID="Content1" ContentPlaceHolderID="init" runat="server">
<%this.Title = "Home Page";%>
</asp:Content>
Make sure you remove the Title="" from the Page directive at the top, or you won't be able to programatically change Page.Title.
I see a lot of people that use the <%= ViewData["Title"] %> option.
I suppose you could also insert a ContentPlaceHolder named Title and then just use that on your page, but in all the MVC examples I've seen, they use the first option.
When I create a new MVC project it has files in there and uses a master page. Looking at that it seems it passes the title to the ViewData as ViewData["Title"] and in the master page, in the <head> there is a script block that outputs ViewData["Title"].
I ended up using a code-behind file to implement Page.Title="..." in the Page_Load() method.
I didn't like doing this, however attempts to implement the change directly in the .aspx page did not work, as it resulted in two <title> tags being present, the one I generated, and the one generated by the Master file the page inherited from.
Ideally, my page code should have overridden the master file's <title> value, but I guess this is just one of those quirks that ASP.Net MVC still has, and one that may already be fixed in a newer version of the ASP.Net MVC Framework (we're still on ASP.Net MVC Beta)
You could do this in your Master Page:
<title>
<%:MyTitle + " :: " %>
<asp:ContentPlaceHolder ID="TitleContent" runat="server">
</asp:ContentPlaceHolder>
</title>
where MyTitle = some value from your web.config or hard text like "My Web"
Now in the view pages (Index for example):
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<%:"My Home Page"%>
Now when you browse your home page, the title would be "My Web :: My Home Page".
I have a base view class that sets the page title from a resource file. Works pretty good for me.
I created a class called Application with a Title property (using get/set):
public static class Application
{
static string title;
public static string Title
{
get { return title; }
set { title = value; }
}
}
I then set the property on the Page_Load event for each page:
Application.Title = "Silly Application";
then i just reference that property on the master page:
<div id="divApplicationTitle">
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx"><asp:Image ID="imgApplicationImage" runat="server" SkinID="skinApplicationLogo" /><%=Application.Title%></asp:HyperLink>
</div>
There is a Title property of the #Page directive for content pages.
For ASP.NET content pages just add Title="" in the <%# %> Placeholder.
We ended up with
<head runat=server visible=false>
in master page.
This way we can read from Page.Title (Page.Title requires head element to exist, otherwise it throws an exception, checked that with reflector). We then use our own head element - MVC way.
You could always use javascript in your view page:
<script type="text/javascript>
document.title = "Hello World";
</script>

Resources