Results 1 to 7 of 7

Thread: Include files within an Include file.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Include files within an Include file.

    Hello,

    I have just started with ASP.NET.

    I like the idea of using Include files so that I can create various versions of individual parts of a site and decide in code which to display. I used:

    <%Response.WriteFile("content\\content.aspx")%>

    to include a content.aspx file within my default.aspx page.

    I would like to include a Left.aspx, Main.aspx and Right.aspx file inside the content.aspx file. I tried using the reponse.writefile function but noticed when I debug the website that the text "reponse.writefile..." displays instead of the code contained within the referenced file(s).

    Can this not be done? Or have I just made a mistake somewhere along the way.

    Thanks

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Include files within an Include file.

    First let me say that i don't like one bit the idea of writefile to render pages like this.
    Now, you can put this, if p.e. you are using a button, in a function. So onbuttonclick you call function 'a' that will call response.writefile.
    I have never seen what you are trying to do and anyhow it's does not seem like a good technique, even if it worked like that.You can either use Iframes to call pages inside a page, or use a function as i've said or you can use master pages.
    If you want to show portions of html when you click on something on the client then just use javascript or jquery to show hide stuff.
    Pages inside a page for no obvious reason seems like a bad idea, only close that i've used it was on a paypal page that i needed multiple 'forms' so i simulated a page like environment because paypal sucks bad when u use it with asp.net and worst when you use it with master pages. But that was an exception i had to make.I don't think you have so complicated problems as you said you just started with asp.net.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Include files within an Include file.

    WriteFile works by taking the contents of the file and sending it right to the response stream. I'm a bit surprised that it runs any ASP code in that included file... because it shouldn't be... it should be sending that file out, as is... which makes me wonder what's really landing in your webpage. Every example I've seen of using WriteFile is to "include" html files... for including other ASP files, I've only ever seen & used the #INCLUDE command.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Include files within an Include file.

    Surprisingly it can be done : http://support.microsoft.com/kb/306575
    Now from what TG is talking about with #Include i am thinking that you are going for the old asp pages style. Haven't noticed that before because i have never used simple asp pages.
    If i am correct i think what you want to do is use master pages. Have a look here for an old to new transition.
    http://www.mikesdotnetting.com/Artic...les-in-ASP.NET
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Include files within an Include file.

    For what it is worth, I would have to agree with Sapator. From what you have described, it would be best to start using the concept of MasterPages, that can then have various areas of a page, header, footer, left pane, right pane, that you can then choose to override, or not, on any given master page.

    In addition, if you are looking to re-use portions of code, or UI, you might want to look at using Custom User Controls, that you could add into the Content Pages of your Master Page.

    Gary

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Re: Include files within an Include file.

    Thank you for all the feedback.

    I realise now that Response.WriteFile is intended for adding static text from an html file or similar and not for including other asp or code files.

    I will look in more detail at the Master page scenario you have kindly suggested.

    At the moment I have managed to get things working by Including HTML only pages within my Default.aspx page using the Response.WriteFile method. And to use other aspx content in that page I have used a Custom User Control that itself can use Response.WriteFile methods to load html content into that part of the page prior to it being displayed in the browser.

    I get the impression that the master page approach would be better than using the above for what I am ultimately doing.. i.e. creating several versions of the footer, header, content-left, content-main, content-right parts of a page and being able to switch between them based on options from a file or mysql table. Is that right?

    However while I am playing with the Custom User Control work around above; is that something you would normally avoid in this kind of scenario or is there any benefit to one approach over the other (e.g. Load Times, Security, Maintainability etc.)?

    Thanks again to you all.
    Jay

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Include files within an Include file.

    Well (anyone can correct if i am wrong) from my point of view you are killing the page performance by using custom user controls in many places because they cannot create asynchronous callbacks altogether. You might incorporate an updatepanel but that will probably make things even worse. I think for code reusage asp.net is not the perfect solution. You can either have a reusable web service that you call or simply copy past portions of jquery or javascript.Haven't given much attention to that part though and i may be wrong.
    Also if you have a user control that fails in some way, your whole page using it may go down. Had that lovable experience with yahoo, given a 404 on a custom control and the page failed with error 500. Had to go through the server logs for hours to find out what the heck was going on.
    So to answer your questions. The master page approach (even if i don't like master pages because they kinda hide the proper html page) is what you need. Forget writefile , it's for special assignments, just drop it. Custom user controls, as i've said, i try to avoid it as much as possible.Load times are slower, security i don't know, you have the login control so no need to re-invent the wheel,maintainability as any self created .net control.
    Again anyone can comment or correct me.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width