为现有网站创建主页的指南

时间:2022-10-19 22:32:56

I've never messed with Master Pages, and I'd like to migrate some of my existing sites over so that I can stop trying to maintain all of the duplicate coding for headers, menus, etc.

我从来没有搞过Master Pages,我想迁移一些现有的站点,这样我就可以停止尝试维护所有的标题、菜单等的重复编码。

I've started with this intro: ASP.NET 2.0 Master Pages - it is pretty good, but doesn't answer my detailed information.

我从这个介绍开始:ASP。NET 2.0母版页面——它非常好,但是不回答我的详细信息。

Can I (and how would I if I can)

我能(如果我能)

  • Master Page the <head><title> tag? (just in case I forget to give a document a title)
  • Master Page the 标签?(以防我忘记给文件加上标题)</li>
  • Master Page the META tags? After all, most of the information is redundant.
  • 主页元标签?毕竟,大多数信息都是多余的。
  • ...and can I add extra to the META tag, or is it an "all or nothing" kind of thing? (like overriding ToString() and returning base.ToString() + " my own flavor.".
  • …我可以给META标签添加额外的东西吗?或者是“全有或全无”之类的东西?(比如覆盖ToString()和返回base.ToString() +“我自己的风格”。)
  • Master Page the CSS Stylesheet page(s) and JavaScript source code?
  • 主页CSS样式表页面和JavaScript源代码?

If it helps, I code using Notepad.exe in Windows 7 because I do not like how most tools (especially Microsoft's tools) try to "auto format" my text for me.

如果有用的话,我用记事本编写代码。因为我不喜欢大多数工具(尤其是微软的工具)试图“自动格式化”我的文本。

Maybe these topics are all basics, but I do not readily see them being answered in the tutorials I'm finding online or the information here.

也许这些主题都是基本的,但是我在网上找到的教程或这里的信息中并没有看到它们的答案。

Could someone point me to a good reference on how to do different things in Master Pages?

有人能给我指出一个关于如何在母版中做不同事情的好参考吗?

1 个解决方案

#1


2  

You can do all of those things with master pages. Just put them in your .master file, similar to this:

你可以用母版做所有这些事情。把它们放在你的。master文件中,类似如下:

<%@ Master Language="C#" AutoEventWireup="True" CodeBehind="YourPage.Master.cs" Inherits="MasterPages.YourMasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Your Title</title>    
    <link rel="stylesheet" href="~/YourStyles.css" />
    <asp:ContentPlaceHolder ID="headContentPlaceHolder" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <div>
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder ID="bodyContentPlaceHolder" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

And FYI: you can turn off auto-formatting in Visual Studio if it bothers you. Using Visual Studio, while not perfect, will help you avoid simple spelling mistakes (via Intellisense) and generally speed up your development, if you learn how to use it. I would recommend using at least some kind of IDE. If not Visual Studio, then maybe MonoDevelop.

顺便说一句:如果Visual Studio让你感到困扰,你可以关闭它的自动格式化功能。使用Visual Studio,虽然不是完美的,但是可以帮助您避免简单的拼写错误(通过Intellisense),并且如果您学会了如何使用它,通常可以加快您的开发。我建议至少使用某种IDE。如果不是Visual Studio,那么可能是MonoDevelop。

#1


2  

You can do all of those things with master pages. Just put them in your .master file, similar to this:

你可以用母版做所有这些事情。把它们放在你的。master文件中,类似如下:

<%@ Master Language="C#" AutoEventWireup="True" CodeBehind="YourPage.Master.cs" Inherits="MasterPages.YourMasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Your Title</title>    
    <link rel="stylesheet" href="~/YourStyles.css" />
    <asp:ContentPlaceHolder ID="headContentPlaceHolder" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <div>
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder ID="bodyContentPlaceHolder" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

And FYI: you can turn off auto-formatting in Visual Studio if it bothers you. Using Visual Studio, while not perfect, will help you avoid simple spelling mistakes (via Intellisense) and generally speed up your development, if you learn how to use it. I would recommend using at least some kind of IDE. If not Visual Studio, then maybe MonoDevelop.

顺便说一句:如果Visual Studio让你感到困扰,你可以关闭它的自动格式化功能。使用Visual Studio,虽然不是完美的,但是可以帮助您避免简单的拼写错误(通过Intellisense),并且如果您学会了如何使用它,通常可以加快您的开发。我建议至少使用某种IDE。如果不是Visual Studio,那么可能是MonoDevelop。