繁体   English   中英

在asp.net文件中使用asp.net代码(由另一个aspx响应)

[英]using asp.net code in a asp.net file (Response.write by another aspx)

我有一个名为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>

当我运行index.aspx文件时,<%Response.Write(“ abc”); %>显示为纯文本...

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

谢谢

与其尝试使用Response.WriteFile("header.aspx") ,不如尝试使用Server.Execute("header.aspx") 这实际上将运行header.aspx文件。 使用Response.WriteFile获取文件的实际内容,并且不执行它。

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

http://msdn.microsoft.com/zh-CN/library/wtxbf3hh(v=vs.100).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM