且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在aspx(.NET)的母版页中使用usercontrol

更新时间:2023-10-03 17:32:04

您面临哪些问题?我可以像正常一样注册UC,并在母版页的代码中添加标签。



 <%@     Master    语言  =  C#    AutoEventWireup   =  true    CodeFile   =  MasterPage.master.cs   继承  =  Master_MasterPage   %>  
<%@ 注册 Src = 〜/ UserControls / EmployeeSearch.ascx TagPrefix = uc1 TagName = EmployeeSearch %>

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > < / title >
< asp:ContentPlaceHolder id = head runat = 服务器 >
< / asp:ContentPlaceHolder >
< / head >
< body >
< 表格 id = form1 runat = server >
< uc1:EmployeeSearch runat = 服务器 ID = ucEmployeeSearch / >
< div >
< asp:ContentPlaceHolder id = ContentPlaceHolde r1 runat = 服务器 >

< / asp:ContentPlaceHolder >
< / div >
< / form >
< / body >
< / html >


i wan to use an usercontrol (aspx) in a masterpage (in content pages) bu i can't. is there any sample to explain how to solve my problem.

What I have tried:

usercontrol (aspx) in a masterpage (in content pages)

What issues are you facing? I can just Register the UC like normal and add the tag in the code for the master page.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Master_MasterPage" %>
<%@ Register Src="~/UserControls/EmployeeSearch.ascx" TagPrefix="uc1" TagName="EmployeeSearch" %>

<!DOCTYPE html>

<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">
        <uc1:EmployeeSearch runat="server" ID="ucEmployeeSearch" />
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>