如何在aspx(.NET)的母版页中使用usercontrol [英] How can I use an usercontrol in a masterpage in aspx (.NET)
本文介绍了如何在aspx(.NET)的母版页中使用usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在主页(内容页面)中使用usercontrol(aspx),但我不能。是否有任何样品可以解释如何解决我的问题。
我尝试过:
主页中的usercontrol(aspx)(在内容页面中)
解决方案
您面临哪些问题?我可以像正常一样注册UC,并在母版页的代码中添加标签。
<%@ Master 语言 = C# AutoEventWireup = true CodeFile = MasterPage.master.cs 继承 = Master_MasterPage %>
<%@ 注册 < span class =code-attribute> 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 >
< span class =code-keyword>< / head >
< body >
< 表格 id = form1 runat = server >
< uc1:EmployeeSearch runat = 服务器 ID = ucEmployeeSearch / >
< div >
< asp:ContentPlaceHolder id = ContentPlaceHolde r1 runat = 服务器 >
< / asp:ContentPlaceHolder >
< / div >
< / form >
< span class =code-keyword>< / 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>
这篇关于如何在aspx(.NET)的母版页中使用usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文