Hi there,
Does anyone know the right way to declare an include file in an aspx page?
Cheers
Si
| SitePoint Sponsor |




Hi there,
Does anyone know the right way to declare an include file in an aspx page?
Cheers
Si


There isn't one. Classic ASP includes have no place in .NET, it's a totally different architecture and there are totally different ways of doing things
.
Nick Wilson [ - email - ]




Hi there again,
In .Net the classic <!-- #include virtual="Blah"--> works. Here is the problem. Take the default page
____Default.asp________
#include topmenu.asp(% javascript sources)
#include leftmenu.asp (Html, Javascript)
then there is the content.
All this works without .net as that is how it is set up now. When you try to do the same in .Net IIS doesn't know/understand what to do with topmenu.asp cos it contains links to the javascript source file (.js).
Anyone have any ideas?
If the above doesn't make sense or need more info please contact me.
Si
You need to create your "include files" as Server Controls.
Then you reference them like so (in your "main" file)
The tag prefix would be your "namespace", for example your company name, "MyTags", etc. Both that attribute and tagname is up to you. The src, ofcourse, references the actual "include file". Note that the default extension for a user control is .ascx. Not sure if this is strictly enforced or not. If you use VS.NET, this is the default.Code:<%@ Register TagPrefix="YOURTAGPREFIX" TagName="YOURTAGNAME" src="filename.ascx"> <html><body> blahblahblah.... <form runat=server> <YOURTAGPREFIX:YOURTAGNAME id="Control1" runat="server" property1="blah" property2="blahblah" /> </form> blahblahblah </body></html>
Ofcourse, your actual "include file", or user control, shouldn't contain any <html></html> statements, since that would mess up the page flow. Also, please note that you can include properties that are sent back to the custom control, like arguments to functions.
I got all this from "Sams Teach Yourself ASP.NET in 21 Days".
**Henning K. Pedersen**
Forbrukerkraft Norway A/S
Bookmarks