C# 在asp.net文件中使用asp.net代码(另一个aspx的Response.write)

C# 在asp.net文件中使用asp.net代码(另一个aspx的Response.write),c#,asp.net,C#,Asp.net,我有一个名为header.aspx的asp.net文件,它是index.aspx的一部分,下面是index.aspx的代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/

我有一个名为header.aspx的asp.net文件,它是index.aspx的一部分,下面是index.aspx的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>

    <!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></title>
    </head>
    <body>
    <% Response.WriteFile("header.aspx"); %>
    <% Response.WriteFile("body.aspx"); %>
    <form runat="server">
    <%= content %>
    </form>
    </body>
    </html>

在header.aspx中:

        <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
    <form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" class="style1">
    <tr>
        <td><img src="images/Banner.jpg" width="990" height="150" /></td>
    </tr>
    <tr>
        <td>
            <img src="images/HomeTopMenu.jpg" width="140" height="30" /><img src="images/AboutTopMenu.jpg" width="140" height="30" /><img src="images/PublicationTopMenu.jpg" width="195" height="30" /><img src="images/FormTopMenu.jpg" width="205" height="30" /><img src="images/LinkTopMenu.jpg" width="160" height="30" /><img src="images/ContactTopMenu.jpg" width="150" height="30" />
            <% Response.Write("abc");  %>
        </td>
    </tr>
</table>
    </form>

.style1
{
宽度:100%;
}
当我运行index.aspx文件时,显示为纯文本

如何在header.aspx中使用asp.net代码


谢谢,不要使用
Response.WriteFile(“header.aspx”)
,请尝试使用
Server.Execute(“header.aspx”)
。这将实际运行
header.aspx
文件。使用Response.WriteFile获取文件的实际内容,而不执行它。

看起来您正在尝试实现母版页概念。 ASP.Net提供了一种更简单的方法,以下链接可能会有所帮助:


你想解决什么问题?响应。Write正在按预期工作