日期:2014-05-17  浏览次数:20446 次

我擦,ASP.NET带母版页的页面都不会建了!
嗯,先建立个用户控件:WebUserControl1.ascx,里面放个按钮,然后建立个母版页:Site1.Master,拖进去上述用户控件和一个多选钮,再建立个带模板页的web:WebForm1.aspx

结果是运行没运行多选钮和按钮都没显示出来,我郁闷。

详细代码干脆贴出来了。

(WebUserControl1.ascx)
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication5.WebUserControl1" %>
<asp:Button ID="Button1" runat="server" Text="Button" />


(Site1.Master)
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication5.Site1" %>
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!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>
  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
   
  <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
   
  </asp:ContentPlaceHolder>
  </div>
  <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
  <asp:CheckBox ID="CheckBox1" runat="server" />
  </asp:ContentPlaceHolder>
  </form>
</body>
</html>


(WebForm1.aspx)
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>


------解决方案--------------------
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication5.Site1" %>
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!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>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">


</asp:ContentPlaceHolder>
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />

</div>
<asp:ContentPlaceHolder ID="ContentPlaceHold