如何将常见的头文件页面放入另一个页面? Asp.net [英] How to put common header file page into another page? Asp.net

查看:52
本文介绍了如何将常见的头文件页面放入另一个页面? Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET中有一个MasterPage,可以为我的应用程序页面创建一致的布局,但有些页面放在单独的文件中,因此它没有MasterPage。



我还有一个单独的文件页面WACHeader.ascx用于标题。



所以我想做的是放一个共同的标题或共同的布局在单独文件中的页面。



如何在单独的文件页面中添加MasterPage而不会出现错误?



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?

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





因为我每次添加





Because every time I add

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

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





但标题不显示。



我想连接WACHeader页面到TestLogIn页面但是如何?



请帮帮我。谢谢。



But the header doesn't show.

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

Please help me with this. Thanks.

推荐答案

只需在主页引用不在的页面中的body标签后添加 UserControl 补充说,它将像普通标题一样

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" />


简单添加MasterPageFile引用将无效,你还将内容移动到ContentPlaceHolder?



这里我建议,打开一个当前使用母版页的XYZ.aspx文件,然后将它与TestLogin进行比较页。修改TestLogin页面结构以匹配XYZ.aspx。例如,如果你看一下XYZ.aspx,你看到doctype,html,head,body ......元素吗?那么XYZ页面内容包含哪个元素?





.net - 如何将母版页分配给现有的.aspx页面? - 堆栈溢出 [ ^ ]
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[^]


这篇关于如何将常见的头文件页面放入另一个页面? Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆