• content控件(24)


    今天重装了系统,同时也装上了vs2010,看看这个编程的东西如何,首先感觉打开时的页面页面蛮好看的,给人以现代感的视觉,神舟龙 然后自己新建了个web站点,里面直接有不同于vs2008的实例,用F5在浏览器中查看,效果 home和page选项是在源代码中没有连接的,怎么实现的哪?手头资料中没有,百度了一下,原来用的是content控件,content 控件是内容页的内容和控件的容器。Content 控件只能和定义相应的 ContentPlaceHolder 控件的母版页一起使用。Content 控件不是独立的控件。该控件包含呈现到母版页中的 ContentPlaceHolder 控件的文本、标记和其他服务器控件。

    <asp:Content
        ContentPlaceHolderID="string"
        EnableViewState="True|False"
        ID="string"
        runat="server">
        Visible="True|False"
            <!-- child controls -->
    </asp:Content>

    也就是说先对ContentPlaceHolder控件进行定义,才能对content的控件定义,content的控件的定义包含对ContentPlaceHolder控件的应用,这是必须的。我们首先使用一个 ContentPlaceHolder 控件来定义内容区域。

    <%@ 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>MasterPage Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:contentplaceholder id="ContentPlaceHolder1" runat="server" />
        </div>
        </form>
    </body>
    </html>

    然后在 Content 控件模板中定义的文本、标记和任何服务器控件呈现到母版页上的 ContentPlaceHolder

    <%@ Page Language="C#" MasterPageFile="~/MasterPageSample_1cs.master" Title="Content Page"%>
    
    <asp:content 
        runat="server"
        contentplaceholderid="ContentPlaceHolder1" >Hello, Master Pages!</asp:content>

    在看一下vs2010给的示例:

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="learn._Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
            Welcome to ASP.NET!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </h2>
        <p>
            To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
        </p>
        <p>
            You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
        </p>
    </asp:Content>

    这里是对ContentPlaceHolder控件的引用真正的contentplaceholder控件是在.master文件总定义,一下为在.master文件中定义的ContentPlaceHolder控件:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="learn.SiteMaster" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head runat="server">
        <title></title>
        <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
        <asp:ContentPlaceHolder ID="HeadContent" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form runat="server">
        <div class="page">
            <div class="header">
                <div class="title">
                    <h1>
                        My ASP.NET Application
                    </h1>
                </div>
                <div class="loginDisplay">
                    <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                        <AnonymousTemplate>
                            [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                            [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
                        </LoggedInTemplate>
                    </asp:LoginView>
                </div>
                <div class="clear hideSkiplink">
                    <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <Items>
                            <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                            <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                        </Items>
                    </asp:Menu>
                </div>
            </div>
            <div class="main">
                <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="footer">
            
        </div>
        </form>
    </body>
    </html>

    vs2010提供的母版能够大大节约编程者的时间,提高工作效率,母版就像大的自定义控件一样,可以灵活的运用到相同模块中。一下为效果图:

    效果

    vs2010的破解方法:http://www.cnblogs.com/shenzhoulong/archive/2010/05/13/1734770.html

  • 相关阅读:
    如何快速正确的安装 Ruby, Rails 运行环境
    五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT) – 整理
    CocoaPods安装和使用教程
    ARC下需要注意的内存管理
    iOS 遍历某一对象的属性和方法
    使用命令行工具运行Xcode 7 UI Tests
    手势知多少
    Customizing UIWebView requests with NSURLProtocol
    iOS: JS和Native交互的两种方法
    NSURLProtocol
  • 原文地址:https://www.cnblogs.com/shenzhoulong/p/1750173.html
Copyright © 2020-2023  润新知