Error on Adding Master Page. - asp.net

I have a using ASP.net C# firstly I have created a webform FrmFirst.aspx. Then I have created a master page. Now I have to add my first page to master page then I am facing the same error :
I am using this code to add my first page to Master page
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="FrmCustomerMaster.aspx.cs" Inherits="FrmCustomerMaster" %>
Tell me my Problem !! Thanks ....

You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders
see LINK
if your master page contain this code
<asp:contentplaceholder id="Main" runat="server" />
your page that Inherits from master should have
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
</asp:Content>

Related

How to show an outside website like google or bing within a master page

I have created a website using a master page. One of the links within the master page is for Googles website. I can display the google website within the master page by inserting the website within a Iframe, but the problem is when I do a search in google and I click on the links some of the links within google do not open. After some reading I find that some websites do not allow their sites to open within an iframe "You have to check for HTTP response header X-Frame-Option of those sites. if its value is "DENY or SAMEORIGIN", then you can not load those website in the iframes.".
So does anyone know of another way to display an outside website within a master page?
This is my content page
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Google.aspx.cs" Inherits="OnCallWeb.Google" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<p>
<iframe src="https://www.google.com/webhp?igu=1" style="width:100%;height:700px;"></iframe>
</asp:Content>
This is on my master page.
<li>Google</li>
Found Google no longer supports Iframes

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)

ASP.NET Ajax Accordion Control not working properly with ScriptManager

I've been reading SO for a while now, but that's the first time I post a question (first time I don't find the answer of what I'm looking for)
Here is my setup:
Master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Master.master.cs" Inherits="VatechWebsite.Master" %>
<html>
<head>...</head>
<body>
<form>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
...
<asp:ContentPlaceHolder ID="content" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
Content page:
<%# Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Brand.aspx.cs" Inherits="VatechWebsite.Brand1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
<asp:Accordion ID="CategoriesAccordion" runat="server" HeaderCssClass="AccordionHeader">
<HeaderTemplate><%# DataBinder.Eval(Container.DataItem, "CategoryName") %></HeaderTemplate>
<ContentTemplate>
<div id="ProductList">Some text<br />supposed to be very large <br/></div>
</ContentTemplate>
</asp:Accordion>
<asp:Content/>
When I run this page, the accordion displays correctly, binds data correctly, and has the first pane expanded. The problem is, I cannot expand/collapse a pane. It seems that the javascript associated with this control is not running correctly. If I replace ScriptManager in the master page with a ToolkitScriptManager, the problem is solved; but I don't want to do that because I have other pages that need the ScriptManager.
I read that the ScriptManager should be adequate for running asp ajax controls, so why is it not working in this case?
If you're stuck with one ScriptManager for some pages, and ToolKitScriptManager for another, there are ways to use the same master page on all your pages, and use different ScriptManager on different pages.
This answer details a few approaches, one approach will disable Master.ShowScriptManager = false; on PageLoad.
Disable ScriptManager on certain pages
Another suggests having different ScriptManagers on for different ContentPlaceHolders, which also works.
Hope this helps!

using a masterpage's namespace from content page

Can i use namespace which is imported on masterpage ?
i can import and use namespace on masterpage like that..
<%# Import Namespace="utl=portal.lib.SnkUtilities" %>
and on markup;
<a href='<%= "/" + utl.getSomeString() + "/cart.aspx" %>'>
but if want to use same namespace on a contentpage, i have to import same namespace on content second time as follows:
<%# Page Title="" Language="C#" MasterPageFile="~/Master" AutoEventWireup="true" CodeBehind="Account.aspx.cs" Inherits="portal.secret.Account" %>
<%# Import Namespace="utl=portal.lib.SnkUtilities" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%= utl.getAnotherString() %>
</asp:Content>
Do you have any suggestions ?
Thanks in advance
You are thinking that the master page is read first, but in the page life cycle, the master page is read after the Page Request, so you have to include the namespace in every page. It first looks in the current page and if it does not find it at the compile time, you will get error.
When the page is fetched, the # Page directive is read. If the directive references a master page, the master page is read as well. If this is the first time the pages have been requested, both pages are compiled.
Read from the End of the page Run-time Behavior of Master Pages
Note that the master page becomes a part of the content page. In effect, the master page acts in much the same way a user control acts — as a child of the content page and as a container within that page.

ASP.NET MVC RC2 template head after body?

When I installed ASP.NET MVC RC2, I noticed that the template had changed from RC1. Now, all new views have the header placeholder after the main content place holder. Why is this? It seems very illogical to me and it most definitely was not the case with RC1. I googled but couldn't find any reasoning for this change. Do you know of any?
Example:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Rules</h2>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
Note how the placeholder with ContentPlaceHolderID of "head" is at the bottom? Weird...
I can't say I noticed it when I upgraded, but it shouldn't matter. The two <asp:Content> sections get mapped by the ID property to their places as defined in Site.master.
Definitely check the order in Site.master, but it should be fine.
If you want to change this, you can look into the T4 template your views are using. Check out:
t4-templates-in-asp.net-mvc
t4-templates-a-quick-start-guide-for-asp-net-mvc-developers
overriding-global-t4-templates-in-asp-net-mvc-project-with-per-project-templates

Resources