[thelist] vb.net: using subroutines within user controls - .ascx

Gary McPherson lists at ingenyus.net
Mon Oct 11 19:02:26 CDT 2004

----Original Message----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Casey Crookston
Sent: 11 October 2004 23:47
To: Casey Crookston; thelist at lists.evolt.org
Subject: Re: [thelist] vb.net: using subroutines within user
controls - .ascx

> Okay,  I'll make this as simple as I can think to make it.
> I'm trying to build a dynamic template site. On every page
> (default.aspx, about.aspx, contact.aspx) etc, I don't want to include
> the same HTML for 
> the header over and over and over again, so I took out the
> basic header that gets re-used on every page and stuck in
> into a seperate file, called HEADER.(i'm not sure of the best
> extension to use yet...) 
> Now, within HEADER.ascx/aspx/inc, there is a little bit of
> dynamic content, nothing serious.  I'd like to put everthing
> in the HEADER file inside a subroutine (called HEADER), so
> that on the main pages (contact.aspx, about.apsx, etc) all I
> have to do is CALL HEADER.
> Does that make sense?
> So, again, this was such a simple task in classic asp.  Not
> so simple ASP.NET, i guess?
> Thank you!!!
> Casey
> P.S.  Please assume I know NOTHING when replying to this message!!

Hi Casey. Yes, I can tell by the methods you're trying to use that you are
definitely an old-school ASP coder. There is a shift in thinking required to
move from ASP to ASP.NET, but it's not a terribly big one. The fundamental
ways in which we build pages is very different, so you really need to get
your head around the ".NET way" if you're going to start making real
progress. There are endless sites and articles to help you to this aim,
Microsoft and GotDotNet are as good a place to start as any, plus there are
links to some worthy articles here: http://aspnet.4guysfromrolla.com/

Anyway, back to your example, the simplest way would be to create a user
control (.ascx) and drop it on every page you have. You would then run your
code in the Page_Load sub and you don't need to call it from your containing
page at all. Just add the to your pages as required and job's done. Of
course, you could take it a step further and use some templating technique
(e.g. MasterPages) but for now, I think the method I just described would
satisfy the example you gave.

Hope that helps,


More information about the thelist mailing list