how to apply master page to pages in asp.net 2008 - asp.net

I am using .net 2008 for developing web application.
So I created a master page and some other pages. I want to apply master page to all other pages but I'm not getting it. Earlier i use .net2005 here there is option when we created a new page in application and check the master page option, but in .net2008 this option is not there so please tell me how to do it. I'm new to .net 2008 .
Please tell me
Thank you

If you want to manually set the masterpage for pages you have already created you can do the following: In the Page directive of your ASPX pages you set the masterpage like this:
<%# Page Language="C#" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page"%>
Your MasterPage defines a few Content areas. You then should reuse those in your page and fill them with the local content.
When adding a new page the documentation says that when adding a Web Forms page you can select the Select master page check box, and then click Add. Then the Select a Master Page dialog box should appear.

You indicating that in your question
"when we created a new page in application and check the master page option"
If you are using a web application when you wan't to add a page with masterpage
you should add the page like this
Project ->
Add New Item ->
Web Form Using Master Page (instead of selecting Web Form)
Then you will have the option to select the masterpage

Use this code:
<%# Page Title="test" Language="VB" MasterPageFile="~/MasterPageName.master" AutoEventWireup="false" CodeFile="PageName.aspx.vb" Inherits="PageNameClass" %>
<asp:Content ID="Content1" ContentPlaceHolderID="maincontent" runat="Server">
//here you can add you page data start from form tag till end of form tag and remove everything else.
</asp:Content>

Related

ASP.NET Master Page on file in folder(s)

I have a small problem with an ASP page. I have a master file and it works great on all pages in the ROOT; however, if I create a folder (say: reports and folder insider there called userRpts) and add a page, the master doesn't apply.
So, I have a fodler structure like:
/reports/UserRpts/UserData.aspx
Master is set as: MasterPageFile="~/MasterPage.master" in the <%# Page %>
Yet it doesn't apply. Any thoughts?

How to Convert ContentPage to WebForm using Visual Studio

I've created some Asp.net pages as ContentPages and I got a request to change these pages as pop-ups instead of opening in the contents of a master page.
Is there a way to convert ContentPages to WebForms using Visual Studio built-in functionality or I must adjust the design of each manually ?
Not sure if there is any inbuilt solution present (most probably NO) but one solution is to remove the master page section MasterPageFile="~/some_name.master from your page design section. Like,
Change this
<%# Page Language="C#" MasterPageFile="~/some_name.master" ...
To
<%# Page Language="C#" ...

How to change content of master page dynamically

I am developing a master page for an e-commerce website. I have Left-Side Menubar on the Master Page. This left menubar contains Category list and changes as user change categories. Categories are stored in SQL DB. So, I want to rebuild this menubar as category changes, Is it possible?
Have look on www.actgreen.com.au/www
And also I want to create Breadcrumb for website, how can I do.
I am using asp.net 4.0.
Thanks.
Well , we don't know what exact approach you are using in your code to bind left menu..Also you must be binding your left menu in your master page itself. So on each time you click on left menu you can rebind it again by providing some parameter to it.
or if you need to call it from some different page or from your content pages..then you can try it like this..
System.Reflection.MethodInfo mInfo = this.Page.Master.GetType().GetMethod("RefreshLeftMenu");
mInfo.Invoke(this.Page.Master, null);
I do it this way...hope its helpful for you too..
You can use controls on masterpage and change them on page OnLoad
Label MyLabelBrand = (Label)Master.FindControl("LabelBrand");
MyLabelBrand.Text = "Fabrikam";
If you want to call method Refresh() of Master page, you need call Master.Refresh();.
To do this you need register master type on ContentPage:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%#MasterType VirtualPath="Site.Master" %>

Accessing ASP Master Page Properties

I have an ASP.net page which uses a master page. The master page has a public property. Does anybody know how can I access the given property from a content page that uses the master page?
Look into Strongly Typing your Master Page link
Check out the <%# MasterType virtualPath="~/MasterPage.master"%> tag.
This enables you to directly have access to the public properties/methods.

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