Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a MasterPage in ASP.NET that creates consistent layout for the pages of my application but there are some pages that are put in separate file so it doesn't have a MasterPage.

I also have a separate file page WACHeader.ascx for header.

So what I want to do is put a common header or the common lay out to the pages that are placed in separate file.

How can I add the MasterPage in the separate file page without getting an error?

ASP.NET
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestLogin.aspx.vb" Inherits="ECM.TestLogin" %>


Because every time I add

HTML
MasterPageFile="~/masterpage/ECM_MasterPage.master"


I get an error

Content controls have to be top-level controls in a content page or a nested master page that references a master page.


How can I put my common header?

What I have tried:

I tried this

ASP.NET
<head runat="server">
    <link id="Link1" runat="server" rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <title>ECM Test Login</title>
    
    <link rel="stylesheet" href="cssFramework/ecmStyle2.css" type="text/css" media="screen, projection" />
    <link href="WAC/WACHeader.ascx" type="text/asp" />
</head>


But the header doesn't show.

I thought of linking the WACHeader page to TestLogIn page but how?

Please help me with this. Thanks.
Posted
Updated 5-Apr-17 17:23pm
v3

just add the UserControl soon after the body tag in the pages where master page reference is not added, it will act like common header
<body>
    <form id="form1" runat="server">
        <uc1:WACHeader runat="server" ID="WACHeader" />
 
Share this answer
 
Comments
RKeyy Sii 5-Apr-17 23:21pm    
uc means for user controls right? Do I need to put something for that? I got an error 'Unknown server tag 'uc1:WACHeader'.

It says 'Unrecognized tag prefix or device filter 'uc1', I'm sorry I'm not familiar with this. Can you explain it to me? Thanks
Karthik_Mahalingam 5-Apr-17 23:29pm    
just drag and drop the file from the solution explorer, it will format the tag automatically.

since you have used ascx file, i assumed that you have used user control
RKeyy Sii 6-Apr-17 1:36am    
Thanks :)
Karthik_Mahalingam 6-Apr-17 1:40am    
welcome :)
Simple adding the MasterPageFile reference will not work, did you also move the content into a ContentPlaceHolder?

Here what I would suggest, open a file XYZ.aspx that is currently using the master page, then compare it with TestLogin page. Modify the TestLogin page structure to match XYZ.aspx. For instance, if you look at XYZ.aspx, do you see doctype, html, head, body... elements? Then which element the XYZ page contents wrap into?


.net - How to assign a master page to a existing .aspx page? - Stack Overflow[^]
 
Share this answer
 
Comments
RKeyy Sii 5-Apr-17 23:31pm    
I tried this already, I modified the TestLogin page to match the page that is currently using the master page. And I got an HTTP Error 404 - Not Found. when I run my application.
Bryian Tan 5-Apr-17 23:42pm    
I don't think that error had anything to do what you did. That HTTP Error 404, sound like the page TestLogin.aspx not there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900