Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't render User Control in an ASP.NET page

Reply
Thread Tools

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

 
 
Steve Gelfmann
Guest
Posts: n/a
 
      06-21-2004
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.
 
Reply With Quote
 
 
 
 
Lau Lei Cheong
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> ???
news:(E-Mail Removed) om ???...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing rails render method outside of view / Decorating render Glenn Gillen Ruby 0 11-17-2006 02:30 PM
Render an User Control inside a mail body without having any Page reference Henri ASP .Net 0 12-11-2004 03:36 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net Building Controls 1 07-02-2003 08:05 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net 0 07-01-2003 09:26 PM



Advertisments