Resources regarding sidebar in master page - asp.net

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.

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

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.

How to position my WebForm where I want it to be *sigh*....?

Check out how it looks right now:
How can I make the ContentPlaceHolder go where I outlined? Thanks for the help.
I mainly program in WinForms, so I'm used to just dragging things around. Why can't I do this here. Help me SO!
Edit: Here's what I have in my CSS:
.Form
{
position:absolute;
left:60px;
}
How can I use this on my Form code:
<%# Page Title="" Language="C#" MasterPageFile="~/EndUserMasterPage.Master" AutoEventWireup="true" CodeBehind="RegistroNuevoPostulante.aspx.cs" Inherits="WebSite.RegistroNuevoPostulante" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
Screw the designer and learn HTML and CSS to understand what's going on.
I mainly program in WinForms, so I'm used to just dragging things around. Why can't I do this here.
Because the markup engine follows different rules. It's not like you have a screen of pixels and you have a complete control over each.
What you absolutely need to learn is the difference between Block-level elements and Inline elements and the Box model. Before you understand at least that, it will be difficult to accomplish anything.
You'll need to get your hands dirty. What you expected the designer to do (a Windows Forms like behavior), was formerly called grid layout which was a feature of ASP .NET 1.x. It was removed. As you would expect it only rendered "well" (theoretically) on Internet Explorer.
I recommend you to go through some css tutorials on w3schools. This link could be a start point. You'll need to learn a couple of div styling attributes to achieve what you want like float, margin and padding.
You could also try the reverse engineering approach and get a free template from oswd, where I'm sure there's a template that addresses your issue. You could use firefox+firebug to learn how everything was achieved.
You can accomplish only the simplest of things with the visual designer. If you actually want to get anything done, you need to get into the source view.
The code you should use will involve something like putting a left margin on the ContentPlaceHolder. This can be accomplished using something like:
<div style="margin-left: 200px;">
<asp:ContentPlaceHolder ... ></asp:ContentPlaceHolder>
</div>
Note that this should go in your master page, not your form.
I guess this should work:
<div id="divX" class="yourCssClass">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"></asp:Content>
</div>
I don't find any problem in this code and I'm sure you can easily place the child page contents anywhere using the CSS(defining yourCssClass).
PLEASE NOTE THIS IS THE CODE YOU NEED TO WRITE IN MASTER PAGE.
Define the CSS class in the master page itself if you want this to be consistent throught out the website or define it in specific pages accordingly. If you don't know CSS, a little bit is below:
.yourCssClass
{
margin-left: 60px;
}
I guess for the same solution given by "recursive", you implemented it on the child page(content webform) due to which you got the error "Content Is Not Supported outside script"! Am I right Papuccino?

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