我的源代码管理中有一个表单列表。
ContentRequest.aspx
ContentRequest.aspx.cs
Default.aspx
Default.aspx.vb
我必须使用其中一些表单来创建其他表单,使用上述表单之一作为各种模板。
我不知道该怎么做。有人可以给我一些指导吗?
-KT
您可以简单地创建要复制的整个 ASPX 表单的副本。在 VS 中,在解决方案资源管理器中右键单击您的项目(网站) -> 添加 -> 新建 -> Web 表单。命名它NewName
。然后从 Default.aspx 复制到 NewName.aspx 并对 aspx.cs 文件执行相同操作。
然后你必须在第一行更改 NewName.aspx 文件的源代码:
CodeFile="Default.aspx.cs" Inherits="_Default" -> CodeFile="NewName.aspx.cs" Inherits="_NewName"
并在 NewName.aspx.cs 文件中:
class _Default : Page -> class _NewName : Page
如果您只是复制 ASPX 文件,复制粘贴是一个好的开始。如果您需要更详细一点(并以正确的方式进行),那么您应该考虑使用母版页作为主题/布局,然后创建继承自它的新表单。
布局大师
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
<title>Master page title</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><asp:contentplaceholder id="Main" runat="server" /></td>
<td><asp:contentplaceholder id="Footer" runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>
内容请求.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPages/Layout.master" Title="Content Request"%>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
</asp:content>
默认.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPages/Layout.master" Title="Default"%>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
</asp:content>