Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2003, 11:43 AM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Include Files

I'm new to ASP.NET and have been reading about using the include directive in the Global.asax

In the Help under server-side include directives it says that the format s

When I try to do this I get a compile error. I want to try and add a footer to every page on my site using the include. Where/how do I do this
 
Old June 21st, 2003, 12:48 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to james_sellwood
Default

As far as I know ASP.NET does not use Includes (like ASP). Instead it uses something called User Controls. These are created within separate files (with a .ascx extension) and then imported into the .aspx file. User Controls cannot contain a form tag. They must be imported within the form tags in the .aspx page. This makes the code work as though it was always within the .aspx page.
Before importing the .ascx file into your .aspx page you need to register a tag that you will use to do the importing with:
Code:
<% @Register tagprefix="usercontrol" Tagname="footer" src="footer.ascx" %>
The above code will register the usercontrol tag for your use. This code would go at the top of your .aspx page along with any necessary namespace imports.

To include the .ascx code at a particular position in your .aspx page you now need to use the tag you just registered.

Code:
<usercontrol:footer id="footer1" runat="server"></usercontrol:footer>
By specifying an id for the control you allow yourself the ability to call any subprocedures or functions within the user control. (By first referencing the id e.g. footer1.mySub() ).

Hope that helps


--------------------
:) James Sellwood :)
--------------------
 
Old August 8th, 2003, 09:31 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can the usercontrol files have codebehind files themselves ? i tried to include one and got an error about only having one @page declaration allowed...

 
Old August 13th, 2003, 12:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default


Yes, user controls can have code-behind files. You need to declare the user control class like so:

  Public Class MyUserControlClass : Inherits UserControl

as opposed to declaring the class as "Inherits Page".

Cheers!

Marlon Villarama
Support Team
Web Burner Hosting
www.webburner.com
877-535-2876





Similar Threads
Thread Thread Starter Forum Replies Last Post
include files b00gieman Classic ASP Basics 2 September 15th, 2007 10:22 AM
Include files tarang SQL Server 2000 1 July 18th, 2007 03:32 AM
Include files errors ahmedkhadragi C++ Programming 1 December 8th, 2006 08:02 AM
Include Files jmss66 Classic ASP Basics 16 June 9th, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.