0

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 include the control:

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

1 Answer 1

2

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.