开发者

User Control Displaying in Wrong Place

开发者 https://www.devze.com 2023-01-12 15:37 出处:网络
I\'m trying to include a user control in an aspx page, it works fine, but my control does position itself where I want it and always appears at the very top of the page. Could it have something to do

I'm trying to include a user control in an aspx page, it works fine, but my control does position itself where I want it and always appears at the very top of the page. Could it have something to do with the masterpage? I've tried registering the user control in the master page, but I don't know how to reference it in the content page. Any ideas?

In my Default.aspx page I register my usercontrol at the top:

<%@ Language="VB" MasterPageFile="~/Master-Pages/Landing1.master" AutoEventWireup="false" 
Title="Home" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Src="/Controls/News.ascx" TagName="HomepageNews" TagPrefix="uc" %>

Then in my page I try inc开发者_开发百科lude the control:

<asp:Content ID="NewsArea" ContentPlaceHolderID="ContentBottomCol" Runat="Server">
 <%@ Register Src="/Controls/News.ascx" TagName="HomepageNews" TagPrefix="uc" %>
</asp:Content>


To include the UserControl in a page you would register it at the top using a Register directive and then include its tag like any other control.

So:

<%@ Language="VB" MasterPageFile="~/Master-Pages/Landing1.master" AutoEventWireup="false" 
Title="Home" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Src="/Controls/News.ascx" TagName="HomepageNews" TagPrefix="uc" %>
...
<asp:Content ID="NewsArea" ContentPlaceHolderID="ContentBottomCol" Runat="Server">
 <uc:MyNewsUserControl ID="MyNewsUserControl1" runat="server"> </uc:MyNewsUserControl>
</asp:Content>
0

精彩评论

暂无评论...
验证码 换一张
取 消