如有不明白的地方欢迎加QQ群14670545 探讨
如果你是从asp程序员转过来一定不习惯.net的编程风格吧,代码和页面时分离的,asp和php里面时常是引入,比如<!--#include File="xxxxxxx"-->,这个其实在.net里面也有的,而且以好几种方式存在。
1.用户控件,比如你新建一个用户控件ccA.ascx,里面内容为:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ccA.ascx.cs" Inherits="MyWebSiteTest.Controls.ccA" %>
我是ccA控件呈现的
然后在要引入的页面头部先注册:
<%@ Register TagPrefix="ctr" TagName="Text" Src="~/Controls/ccA.ascx" %>
再在需要的地方写入就OK了
<ctr:Text runat="server" />
2.用户控件的嵌套,就是用户控件里面嵌套用户控件,这个道理和用户控件有些类似,但是有些细节需要知道,就是子控件的属性,这里不说了,回头开一个帖子来讲
3.用#include标签来引入
比如新建一个header.inc文件里面写入如下代码:
<div class="top"></div>
<div class="main">
<div class="left"></div>
<div class="right"></div>
<div style="clear:both;"></div>
</div>
然后我们将它直接引入到页面中:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="incfile.aspx.cs" Inherits="MyWebSiteTest.Manager.incfile" %>
<%--<%@ Register TagPrefix="ctr" TagName="Text" Src="~/Controls/ccA.ascx" %>--%>
<!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>页面包含inc文件</title>
<style type="text/css">
bory{ margin:0; padding:0;}
.content{ width:1000px; margin:0 auto; padding:0;}
.top,.bottom{ height:115px; background-color:#7fa9d5;}
.left{ float:left; width:250px; height:600px; border:1px solid #333; background-color:#946;}
.right{ float:right; width:720px; height:600px; border:1px solid #f00; background-color:#95C754;}
</style>
</head>
<body>
<form id="form1" runat="server">
<ctr:Text runat="server" />
<div class="content">
<!--#include File="header.inc"-->
<div class="bottom"></div>
</div>
</form>
</body>
</html>
3.对于普通的htm/html文件包含也就一句话的事,比如:
<!--#include virtual="/_data/shtm/footer.htm" -->