Can't render User Control in an ASP.NET page

Discussion in 'ASP .Net' started by Steve Gelfmann, Jun 21, 2004.

  1. I am new to ASP.NET. So I am trying to learn from the book I just
    bought. There is a simple example of how to build a user control
    which I religiously typed into the Notepad, but the results are not
    what was expected.
    Here's what I did.
    First, I created the user control and saved it in a file
    "SimpleHeader.ascx".

    <%@ Control Language="VB" %>
    <html>
    <head><title>Simple User Control</title></head>
    <body>
    <h2>This is an example of a simple user control</h2>
    <i>Simple Header!</i>
    <hr />

    Then, I created an ASP.NET page called HomePage.aspx that included the
    control.

    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="SimpleUserControl" TagName="Header"
    Src="SimpleHeader.ascx" %>
    <SimpleUserControl:Header
    id="ctlHeader"
    runat="server" />
    Hello!
    </body>
    </html>

    I stored both files in the same folder. When I try to view the page it
    just shows the contents of the HomePage.ascx file.

    What do I do wrong? How to make user control appear on the page?
    Thanks.
     
    Steve Gelfmann, Jun 21, 2004
    #1
    1. Advertising

  2. You'll just see a "UserControl" placeholder there in the IDE unless you run
    the page.

    And in you case you won't see the usercontrol even if you run it because
    both the <html> and <body> tag is missing in the aspx file.

    Note that you can't place the start tag in one file and place the end tag in
    another. In that case the browser and/or web server won't be able to tell
    where your usercontrol should be placed.

    Regards,
    Lau Lei Cheong


    "Steve Gelfmann" <> ???
    news: ???...
    > I am new to ASP.NET. So I am trying to learn from the book I just
    > bought. There is a simple example of how to build a user control
    > which I religiously typed into the Notepad, but the results are not
    > what was expected.
    > Here's what I did.
    > First, I created the user control and saved it in a file
    > "SimpleHeader.ascx".
    >
    > <%@ Control Language="VB" %>
    > <html>
    > <head><title>Simple User Control</title></head>
    > <body>
    > <h2>This is an example of a simple user control</h2>
    > <i>Simple Header!</i>
    > <hr />
    >
    > Then, I created an ASP.NET page called HomePage.aspx that included the
    > control.
    >
    > <%@ Page Language="VB" %>
    > <%@ Register TagPrefix="SimpleUserControl" TagName="Header"
    > Src="SimpleHeader.ascx" %>
    > <SimpleUserControl:Header
    > id="ctlHeader"
    > runat="server" />
    > Hello!
    > </body>
    > </html>
    >
    > I stored both files in the same folder. When I try to view the page it
    > just shows the contents of the HomePage.ascx file.
    >
    > What do I do wrong? How to make user control appear on the page?
    > Thanks.
     
    Lau Lei Cheong, Jun 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    1
    Views:
    5,438
    Christophe Gijbels
    Jan 4, 2004
  2. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,091
    Lau Lei Cheong
    May 15, 2004
  3. Sekhar
    Replies:
    2
    Views:
    1,641
    Steve C. Orr [MVP, MCSD]
    Jul 14, 2004
  4. Dan
    Replies:
    5
    Views:
    371
  5. Dan
    Replies:
    3
    Views:
    832
    Alessandro Zifiglio
    Jan 21, 2004
Loading...

Share This Page