c# - Asp.net 中的母版页未加载代码实现

标签 c# asp.net .net

我是 asp.net 的新手!按照教程 http://www.youtube.com/watch?v=aUx2Bdx68f4我已经编写了成功构建的代码!但是当我执行这个时它显示了以下错误: enter image description here

样式表

body
{
    font-family: 'lucida grande' ,tahoma,verdana,arial,sans-serif;
    background-color: #e9e9e9;
}
#wrapper
{
    width: 1080px;
    margin: 0 auto;
    padding:10px;
    border: 5px solid #dedede;
    background-color: #fff;
}
#banner
{
    height: 200px;
    border: 3px solid #e3e3e3;
    background-image:url(../Styles/kk.jpg);
    background-repeat: no-repeat;
    background-size : cover;   
}
#navigation
{
    height: 60px;
    border: 3px solid #e3e3e3;
    margin-top:20px;
    background-image:url(../Styles/kk.jpg);
}
#content_area
{
    float: left;
    width: 750px;
    margin: 20px 0 20px 0;
    padding: 10px;
    border: 3px solid #e3e3e3;
}
#sidebar
{
    float: right;
    width: 250px;
    height:400px;
    margin:20px 10px 20px 10px;
    border: 3px solid #e3e3e3;
}
#footer
{
    clear:both;
    width: auto;
    height:40px;
    margin-top:20px;
    background-image:url(../Styles/kk.jpg);
}

母版页代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>My Website</title>
    <link rel= "StyleSheet1" type="text/css" href ="~/Style/StyleSheet1.css" />

</head>
<body>
    <form id="form1" runat="server">
    <div id="wrapper">
    <div id="banner">
    </div>
    <ul id="navigation">
    </ul>
    <div id="content_area">
    </div>
    <div id="sidebar">
    </div>
    <div id="footer">
    <p> All rights reserved.</p>
    </div>
    </div>
    </form>
</body>
</html>

谁能帮我解决我的问题?

最佳答案

母版页不是直接执行的,您需要创建 aspx 页面,然后在其中包含该母版页。

将该aspx页面设置为启动页面,然后执行程序。

添加母版页:

您的@page 指令应具有 MasterPageFile="~/MasterPage.master"

属性

您的整个@page 指令应如下所示:

<%@ Page Title="" Language="c#" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ASPXPageName.aspx.cs" Inherits="NamespaceName.ASPXPageName" %>

添加aspx时会有以下步骤:

enter image description here

enter image description here

可以按照下面的文档:

http://msdn.microsoft.com/en-us/library/aa581781.aspx

关于c# - Asp.net 中的母版页未加载代码实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853246/

相关文章:

c# - 您可以调用 Page.ClientScript.RegisterClientScriptBlock 的绝对最新时间是什么时候?

c# - 如何从 WebAPI 中的异常获取 HttpStatusCode?

.net - Selenium 或 Coypu 等待元素显示并在显示前获取时间

.net - 如何实现像 .NET 的 ConcurrentBag<T> 这样的类?

c# - 自定义 ScrollBar 样式神器?

c# - 确定目录中的文件数

c# - 如何将 Find 方法与通用 List 类一起使用以按名称查找特定实例

c# - 当我的方法在后台 WPF 中执行某些操作时,如何打开窗口或其他内容

c# - 网页手机上传

asp.net - 如何在 HttpWebRequest 期间维护 session 值?