locked
Loading ASHX files within ASPX Pages RRS feed

  • Question

  • User-2023406598 posted

    Ok basicly I have about 10-15 projects which all need the same header, and I've been looking into a couple of options when I can across ashx files.

     

    I've found that I can load an ashx file from within an aspx if it outputs javascript like such: 

    <script src="http://www.mySite.com/header.ashx" type="text/javascript" language="javascript"></script>
     
    Or images like such:
    
    

    <img src="http://www.mySite.com/header.ashx" />

     

     

    But I want to be able to load an ashx that includes html outputs (or possibly even asp.net controls).

     

    Is this at all possible? If it is how do I do it??

     

    Thanks in advance.

    Regards

    The Prophet

    Thursday, May 3, 2007 9:58 PM

Answers

  • User-2023406598 posted

    No, with ashx files I can reference them from anywhere on the Net, so I only need to keep one copy somewhere on our intranet and the other sites can reference it, eg:

     <script src="http://intranet/headerApp/header.ashx" type="text/javascript" language="javascript"></script>

     

    Now while I would still like to be able to dump out HTML to the page rather than javascript I have found I can do this:

     Create the ASP Controls, and put them all in a Panel. Then Render the panel and simple use the javascript "Document.write"  eg:

     

    '// Render the Panel control

    Dim sw As StringWriter = New StringWriter()

    Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)

    p.RenderControl(writer)

    '// Emit the rendered HTML

    context.Response.Write("document.write('" & Replace(Replace(sw.ToString(), """", "\'"), vbNewLine, "") & "');")

     

     

    Oh and also thank you for those articles there were an interesting read and should help me with some of my other projects.

     

    Regards

    The Prophet

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 6, 2007 7:08 PM

All replies

  • User-225114762 posted
    It sounds like a job for master pages, provided you're running 2.0 of course. Here's an overview: http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx .
    Friday, May 4, 2007 12:44 AM
  • User-2023406598 posted

    nah, unfortunatly not.  Master pages aren't powerful enough.  You have to add a copy of the master page to every project.

     

    What I need is just on file which can lie anywhere which I can load in.

     

    See I could create a virtual directory within each project pointing to that one location, but that is a pain, and also causes a lot of problems in the development process.

    Friday, May 4, 2007 12:56 AM
  • User-225114762 posted
    Ok... So now you have to add a copy of your ashx file to every project? Or do you want to inject stuff into a number of existing sites? There's a few ideas on subclassing and overriding (i.e. injecting stuff) sites in the two-part article-series by Dino Esposito - check out http://msdn.microsoft.com/msdnmag/issues/07/04/CuttingEdge/default.aspx and http://msdn.microsoft.com/msdnmag/issues/07/05/CuttingEdge/default.aspx .
    Friday, May 4, 2007 3:14 AM
  • User-2023406598 posted

    No, with ashx files I can reference them from anywhere on the Net, so I only need to keep one copy somewhere on our intranet and the other sites can reference it, eg:

     <script src="http://intranet/headerApp/header.ashx" type="text/javascript" language="javascript"></script>

     

    Now while I would still like to be able to dump out HTML to the page rather than javascript I have found I can do this:

     Create the ASP Controls, and put them all in a Panel. Then Render the panel and simple use the javascript "Document.write"  eg:

     

    '// Render the Panel control

    Dim sw As StringWriter = New StringWriter()

    Dim writer As HtmlTextWriter = New HtmlTextWriter(sw)

    p.RenderControl(writer)

    '// Emit the rendered HTML

    context.Response.Write("document.write('" & Replace(Replace(sw.ToString(), """", "\'"), vbNewLine, "") & "');")

     

     

    Oh and also thank you for those articles there were an interesting read and should help me with some of my other projects.

     

    Regards

    The Prophet

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 6, 2007 7:08 PM