ASP.NET WebForms创建UserControl

定义自定义控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="TemplateTest.WebUserControl1" %>
<asp:Label ID="Author_Label" runat="server" Text="Author:"></asp:Label>
<br />
<asp:Label ID="Author_Value" runat="server" Text="Value:"></asp:Label>
<h1>This is atitle</h1>

调用:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TemplateTest.WebForm1" %>
<%@ Register TagPrefix="UC" TagName="Author" Src="WebUserControl1.ascx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
             <UC:Author runat="server" ID="author" />
        </div>
    </form>
</body>
</html>
posted @ 2020-06-18 13:12  Kyle0418  阅读(179)  评论(0编辑  收藏  举报